HI All,
I need help please, with how to make a command, to read the files on my SD card.
I make a list of the file names in a function …
void Get_SD_Names(const char * path) {
SD_ONbus();
X = 0;
File root = SD.open("/");
while (true) {
File entry = root.openNextFile();
if (!entry) {
break;
}
Song_Name[X] = entry.name();
entry.close();
X++;
}
root.close();
}
Song_Name[X] is defined as a string at start of my code … String Song_Name[50];
I can then show a list of the file names Song_Name[X] on my TFT touch screen.
I then have Song_Name[X] buttons, to read the contents of whichever file is selected.
Problem … the names I get are like this “File1.txt” , “File2.txt” , etc … NOT like this “/File1.txt”
When I press a button and then call my “read file contents” functin …
void Read_File_Contents(const char *path) {
… I need to add the “/” to the beginning of the file name, to make a path i.e “/File1.txt”
If I manually use Read_File_Contents("/File1.txt"); it reads the file OK.
However, when I press a button, I need to automatically make a command, somehow like … Read_File_Contents("/" + Song_Name[X]);
… depending which button is pressed, but that doesn’t compile.
How do I combine the “/” onto the string name Song_Name[X] to make a command
Read_File_Contents("/path"); ??
Or, how to read each Song_Name[X] string as the “path” … not just the “entry.name()” ??
Thank you,
Trevor