Go Down

Topic: Store file names from SD card in an array (Read 821 times) previous topic - next topic


This may sound noobie, but I'm stuck on this problem for a few days. I'm trying to store the file names of a directory from an SD card  to an array, but no matter what I try, it won't work :(

I have a global variable for storage:
Code: [Select]
char *sdfiles[200];
And I have two functions, one to read the file names to the array, and an other one to print them through serial.

Code: [Select]
void cacheDirectory(File dir) {
  int i;
  while(true) {

    File entry =  dir.openNextFile();
    if (! entry) {
      // no more files
    sdfiles[i] = entry.name();

Code: [Select]
void printSDCache() {
  Serial.println("SD cache: ");
  for(int i = 0;i <= files;i++) {

And this is how i call them form the setup() :
Code: [Select]
root1 = SD.open("/");

When I call them from the setup() the cacheDirectory() seems to work, when i print the values back after storing them. But when I call the printSDcache() afterwards, i just get memory garbage :( I've tried using String array instead of char*, but that hangs my DUE. I've even tried an array of structs, but that gave me the same result as the char* array.

Any help would be appreciated!
Thank you!

Go Up