I'd like to be able to scroll through some files on an SD card via an LCD. I only want to print certain file types to the LCD screen so my thought was to write a bit of code that nabbed a character array corresponding to the filename (in 8.3 format) and read the last three characters. If those last three characters were "csv" then I would print.
However, after hours of reading forum questions and trying to read through the SD.h and SD.cpp files, I'm no closer to my goal. Right now, I can return a pointer to the actual file name via the function
name(). I want to be able to access the actual file name and store it as a string or an array of characters.
Alternatively, can someone help me understand the
File class? It looks like
openNextFile() returns File(f, name) where "name" looks like it is the character array that I want. How do I access it?
File root;
File entry;
char fileName[12];
char* entryName;
setup(){
root = SD.open("/");
while(1){
entry = root.openNextFile();
entryName = entry.name();
//entryName.toCharArray(fileName, sizeof(fileName)); //this is nonsense
if (! entry) break;
Serial.println(entryName); //prints out the name as expected
//let's pretend like I can get my character array ... then:
if (fileName[10] == 'c' && fileName[11] == 's' && fileName[12] == 'v'){
lcd.println(entryName); //haven't tried this yet and obviously I'd have to setup my LCD first
}
}
}
Or a more elegant solution if anyone cares to share one!