'Arduino: getting filenames using SdFat

I have used SdFat before, but it seems to have changed and I can't find documentation that I understand, and fewer examples... I have an Arduino project in which I am trying to task it job/s based upon files on the sd card. Example: For each *.hex file verify there is a *_out.hex {If not, do work and create one} I have found documentation on SdFile.getFilename(); but compiler tells me there is no member... My current code compiles like this and prints info to the &Serial; however, I need the file name in a variable.

SdFile file;
char *chArray;

while (file.openNext(sd.vwd(), O_READ)) 
{
  file.printFileSize(&Serial);
  Serial.write(' ');
  file.printModifyDateTime(&Serial);
  Serial.write(' ');
  file.printName(&Serial);//->I need this output in char*
  if (file.isDir()) {
    // Indicate a directory.
    Serial.write('/');
  }
  Serial.println();
  file.close();
}

Thanks in advance for everyone's support...



Solution 1:[1]

Here is what I have used to get file name for example for file,

There is a bit of a problem though you need to guess the filename size here I have picked 25 if your file is bigger use a bigger or smaller use a smaller number respectively.

Code

int max_characters = 25;
char f_name[max_characters];
file.getName(f_name, max_characters);
String filename = String(f_name);
Serial.println(filename);

Since you wanted in char*

Modifying your code

SdFile file;
char *chArray;

while (file.openNext(sd.vwd(), O_READ)) 
{
  file.printFileSize(&Serial);
  Serial.write(' ');
  file.printModifyDateTime(&Serial);
  Serial.write(' ');
  file.printName(&Serial);//->I need this output in char*

//bruh here is the code
int max_characters = 25; //guess the needed characters
char f_name[max_characters]; //the filename variable you want
file.getName(f_name, max_characters);
//f_name use for your needs


  if (file.isDir()) {
    // Indicate a directory.
    Serial.write('/');
  }
  Serial.println();
  file.close();
}

I just read what the developer coded in github

https://github.com/greiman/SdFat/blob/master/src/FatLib/FatFile.h

Specifically its mentioned here

bool getName(char* name, size_t size);
 /**
  * Get a file's Short File Name followed by a zero byte.
  *
  * \param[out] name An array of characters for the file's name.
  *                  The array must be at least 13 bytes long.
  * \return true for success or false for failure.
  */

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 AlexSp3