SdFat file index questions

I have some more basic questions about using the SdFat library.

  1. What exactly are file indexes? Does every file and directory on the entire drive have a unique one, or are they relative to each directory? I noticed that I can increment them forever, and they will loop back around. So, file index 10 might open the first file on my sd card, and index 13543 might open the same file.

  2. I know SdFat only supports 8.3 filenames, but does it support the full 65,534 files per directory in FAT32 formatted sd cards?

  3. Is there an easy way to have OpenNext use alpha numeric sorting instead of opening the next file index?

Thanks. These are questions that have been on my mind. Hopefully someone can straighten me out.

What exactly are file indexes?

It is just the position of the file's directory entry in its directory file. Open by index just does a seek to 32*fileIndex and tries to open the directory entry located there.

Only one index should open a given file. Open should return an error if the seek fails or there is not an active directory entry at that location.

but does it support the full 65,534 files per directory in FAT32 formatted sd cards?

Yes SdFat supports the full 65,534 files per directory.

Is there an easy way to have OpenNext use alpha numeric sorting instead of opening the next file index?

No there is no concept of sort in FAT directory files. Files are created using the first found free directory entry. The search algorithm for finding a free entry is not specified in the FAT spec.

One more simple question for you. How can I check the current working directory name? I basically want to do something like this:

if (sd.cwd() == "/00system/logo") {
   doStuff();
}

You can get the filename for the current working directory but not the full pathname.

#include <SdFat.h>
char name[13];  // 8.3 name plus zero byte
SdFat sd;

void setup() {
  Serial.begin(9600);
  sd.begin();
  // name for volume working directory
  sd.vwd()->getFilename(name);
  Serial.println(name);
  
  // name for current working directory
  SdBaseFile::cwd()->getFilename(name);
  Serial.println(name);
}
void loop() {}

For a single SD card cwd is the same as vwd. For multiple SD cards each card has a vwd.

See the TwoCards.ino for an example.

Ok, thank you for the clear explanation.