Hello,
Is it possible to save root filenames to other file like txt?
I would like to get brand new list after pushing button - clearing file etc is no problem.
I have found examples how to "print" filenames to Serial and it is clear, but no idea how "print" it to file in SD card.
in which we are supposed to guess what listFile is an instance of, and what it's printName() method does...
file.printName(&Serial);
Here, we can see that file is an instance of the SdFile class. We can also see that printName() takes the address of a Stream instance where it is to write the name.
If you look at the SdFat.h file, you'll see that SdFile is defined as deriving from PrintFile. If you hunt around, you'll find that SdFile is implemented in FatFile.cpp, which includes FatFile.h. Both of these files are in the utility folder.
If you look at FatFile.h, you'll see that SdFile has a getName() method that allows you to get the name of the file.
char name[80];
int nameLen;
file.getName(name, &nameLen);
Is it possible to list only one type of files? For example .txt.
Yes. You have the name of the file. You can look for the last . in the name, and construct a substring of the rest of the name.. If the substring is txt, write to the file. If not, don't.