The example sketch for "openNextFile()", located here has two flaws: (1) Once in a subdirectory, it never goes back to find more recent files in the root directory. (2) It then endlessly loops through sending "nomorefiles".
So here is my corrected sketch, which I hope you can use to replace the flawed one:
root = SD.open("/");
// nothing happens after setup finishes.
void printDirectory(File dir, int numTabs)
File entry = dir.openNextFile();
if (! entry)
if (numTabs == 0)
Serial.println("** Done **");
for (uint8_t i=0; i<numTabs; i++)
So here is my corrected sketch
Does that even compile for you? For me:
sketch_jun20a.ino:1:9: error: #include expects "FILENAME" or
sketch_jun20a:6: error: variable or field 'printDirectory' declared void
sketch_jun20a:6: error: 'File' was not declared in this scope
sketch_jun20a:6: error: expected primary-expression before 'int'
sketch_jun20a:3: error: 'File' does not name a type
sketch_jun20a.ino: In function 'void setup()':
sketch_jun20a:8: error: 'SD' was not declared in this scope
sketch_jun20a:9: error: 'root' was not declared in this scope
sketch_jun20a:10: error: 'printDirectory' was not declared in this scope
sketch_jun20a.ino: At global scope:
sketch_jun20a:18: error: variable or field 'printDirectory' declared void
sketch_jun20a:18: error: 'File' was not declared in this scope
sketch_jun20a:18: error: expected primary-expression before 'int'
Could you please post your corrected example, preferably after a pass throught the IDE's auto-format tool?