SdFat issue with Filenames

Hello I have below code that works perfectly on SD library , it prints on Serial the filenames of the files in root of the SD

But when I changed the code to use SdFat I have issue because instead of the filenames I am getting back

Serial output when using SdFat library - always use getName

File 1 Name is - use getName()
File 2 Name is - use getName()
File 3 Name is - use getName()

Serial output when using SD Library - Works Fine

File 1 Name is - myf1.NC
File 2 Name is - myf2.NC
File 3 Name is - myf3.NC

Complete codes are attached

Get filename function is below

String getFileName(byte i) {
Returns a filename.
if i = 1 it returns the first file
if i = 2 it returns the second file name
if i = 3 … see what I did here?
byte x = 0;
String result;
File root ="/");

while (result == “”) {
File entry = root.openNextFile();
if (!entry) {
// noting
} else {
if (!entry.isDirectory()) {
if (x == i) result =;
return result;

SDFAT_testcode.ino (1.13 KB)

SD_testcode.ino (1.08 KB)

Here you can see the definition of the name() function in the SDFat library:

  /** No longer implemented due to Long File Names.
   * Use getName(char* name, size_t size).
   * \return a pointer to replacement suggestion.
  const char* name() const {
    return "use getName()";

You can see that the name() function has been discontinued and the library is trying to tell you that you need to use the getName() function instead.

Hello Thanks for the point but in the same file there is no getName() function that can be used

Thanks again

Here's the function prototype:

   * Get a file's name followed by a zero byte.
   * \param[out] name An array of characters for the file's name.
   * \param[in] size The size of the array in bytes. The array
   *             must be at least 13 bytes long.  The file's name will be
   *             truncated if the file's name is too long.
   * \return The value true, is returned for success and
   * the value false, is returned for failure.
  bool getName(char* name, size_t size);

I have to check that but that my function have to completely re write