can i declare a string array, without knowing exactly the number of array?

I am trying to write a function that stores all my filenames inside an array of strings.

basically will use a while loop, then retrieve the filenames, but i do not know before hand how many arrays of the string i should require before hand.

Is there a way to create a string array without knowing how many beforehand? or are there workarounds? open to suggestions. thanks :slight_smile:

im using sdfat library.

  numFiles = 0;
  sd.vwd()->rewind();
  while (file.openNext(sd.vwd(), O_READ)) {
    String filename[numFiles] = file.printName(&Serial);
    numFiles ++;
    file.close();
  }

It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. Just use cstrings - char arrays terminated with 0.

And when you compile the program you will need to allocate the full amount of space you need.

...R

am trying to write a function that stores all my filenames inside an array of strings

Remind us about the constraints on filenames.