How can I work with an array to collect the path file of my SD card

Good evening.

I ma working with an Sd card and I have folders and files following this tructure:

2015/12/21/21/09-11-59.TXT
2015/12/21/23/21-24-17.TXT

Here is my fonction to read the SD card

void printDirectory(File dir, int numTabs) {

  if(numTabs == 0)
  {

  }

   while(true)
   {

     
     File entry =  dir.openNextFile();
     if (! entry)
     {
       // no more files
       SerialUSB.println(F("Break"));
       break;
     }
     
     for (uint8_t i=0; i<numTabs; i++)
     {
       SerialUSB.print('\t');
     }
     
     SerialUSB.print(entry.name(),0);
     
     //strncat(sd_path_file, entry.name(), strlen(entry.name()));
     
     if (entry.isDirectory())
     {
      
       SerialUSB.println("/");
           
       printDirectory(entry, numTabs+1);
     }
     else
     {
       // files have sizes, directories do not
       SerialUSB.print("\t\t");
       SerialUSB.println(entry.size(), DEC);

     }
     entry.close();
   }

It’s works fine and it printed my Sd structure.
It’s fine, but it only display in a Serial Monitor and I can not exploit the the files.
I would like to save the path, or let say the folders, in a variable.

My goal it to work (reading the data) of the latest saved files.

As you can see, there is a variable ‘numTabs’. That variable show the depth of the folders.
For exemple, if numTabs is egal to 0, we are in folder 2015
if numTabs is egal to 1, we are in folder 12
if numTabs is egal to 2, we are in folder 21 ou 23

Is there a way to save a char in an array?

For exemple

char myArray[numTabs][]

to have something like this

// How can I declare it?
myArray[0][] = "2015";
myArray[1][] = "12";
myArray[2][] = "21";
// or
myArray[2][] = "23";

I am a bit confused to be clear in my question but my idea is to use the value of ‘numTabs’ to easly save the folder name and use the content.

I would like to read the content of the newest files, but I need to know it path

How can I save the folder structure in different variable according to ‘numTabs’ value?

Thank for your help and happy christmas first of all!

Is there a way to save a char in an array?

Of course there is. If you are going to have a static, 2D array of chars, you'll need to know how many files there are on the card before the program runs.

If you are going to dynamically allocate memory for each file name, you'll need to deal with the possible failure to allocate memory.

You don't say which Arduino you are using, but 27 characters per file name (including the terminating NULL) means that, on a UNO or other 328-based Arduino, you can store at most 75 file names in the array. Actually, it will be quite a few less than that, since the SD class uses at least 1/4 of the SRAM, leaving room for no more than 55 file names.

For exemple

No. You will need to define with dimensions, since you are not providing any initializers that would let the compiler determine the second dimension. The first dimension is NOT the number of tabs. It is the number of files. The second dimension is the length of the full path to the file (plus one for the terminating NULL).