SD directory listing anomaly

manitou

Senior Member+
Just for the record, I have a SanDisk 8 GB uSD (SDHC, fat32) that has had lots of file activity. A directory listing from SD example listfiles on various Teensy 3* and 4* microSD drives (both SPI and SDIO/BUILTIN)) only lists the first 4 files of the 30 or so files on the uSD?? Using arduino 1.8.15 and TD 1.56, I can still read and write files on the uSD even though the directory list is truncated. The directory is short also if I use SdFat example DirectoryFunctions.

The directory is fine if I insert uSD into Windows 10 or Ubuntu. SD listfiles directory is good on adafruit Adalogger built on Arduino IDE. And directory is good on NXP 1170 SDK FATFS.

The Teensy SD libs don't like a NULL directory entry (?), I can hack listfiles to give a full directory listing with a counter
Code:
...
void printDirectory(File dir, int numSpaces) {
   [COLOR="#FF0000"]int count = 0;[/COLOR]
   while(true) {
     File entry = dir.openNextFile();
     if (! entry) {
       //Serial.println("** no more files **");
      [COLOR="#FF0000"] if (++count > 1)[/COLOR] break;
     }
...

I know i could reformat the card etc., but it would be nice if Teensy Sd libs were more robust.
 
Last edited:
I ran into that a while ago and I think the problem was something to do with there being a windows System Directory (I forget its name) OR there was a file with garbage characters in the name. The listfiles example stopped dead when it got to that entry.
Sorry, can't remember the details now.

Pete
 
Back
Top