I have a micro SD card in a Teensy 3.6. When I use openNext, about half the time it only goes through the first four files but the rest of the time it works. I have not yet tried another SD card.
In the code below, if it only goes through four files, there is about a half second pause between printing the file names and the final newline. This pause is not there if it goes through all the files.
I appreciate the help. Thanks.
In the code below, if it only goes through four files, there is about a half second pause between printing the file names and the final newline. This pause is not there if it goes through all the files.
I appreciate the help. Thanks.
Code:
#include "SdFat.h"
SdFatSdioEX sd;
File dirFile;
void setup(){
Serial.begin(9600);
while (!Serial) {}
if (!sd.begin()) {
sd.initErrorHalt();
Serial.println("sderror");
}
}
void loop(){
if(Serial.available()){
Serial.read();
dirFile.open("/", O_READ);
traverseDirectory(dirFile);
dirFile.close();
}
}
void traverseDirectory (File CFile){
File pdfile;
CFile.rewind();//This is probabably the only rewind that is in any way relevant
pdfile.rewind();
sd.vwd()->rewind();
while (pdfile.openNext(&CFile, O_READ)){
if (pdfile.isHidden()){}
else {
char fileName[64] = {0};
pdfile.getName(fileName, 64);
Serial.println(fileName);
}
pdfile.close();
}
Serial.println();
}