Need a way to retrieve a file name from LittleFS

Hi, I am kind of new to programming in general, but I am making progress.
However, I ran into a problem above my pay-grade and I need a little help.

This involved LittleFS and there is a built in function to read a file name. ‘file.name()’
For instance:
Serial.println(file.name())
This works fine and it prints the file name.but the structure of this function is a follows:
*const char fs::File::name() const

I do not understand this at all but I was trying to find a way to retrieve a file name into a variable so that I can manipulate it.
The file name is never longer than 3 characters so I did make a char array of length 4
char myFileName[4];
and then tried to assign it like this:
myFileName = file.name();

PlatformIO complains that : a pointer to a bound function may only be used to call the function

Can anyone please tell me how I can do this?

Thanks for your help

Sam

Are you trying to rename a file? Then you might want to use the

function of the filesystem directly with the new and old path.

If you want to use the

function to retrieve and modify the file name in a buffer (this doesn’t directly change it on the filesystem!) then you you’d have to string-copy the retrieved name into a buffer of the appropriate size. The function strncpy can be used for that safely. It’s contained in the <string.h> header but that should be auto-included by Arduino.h.

E.g.:

char myFileName[4] = {0};
// copy current file name into buffer
strncpy(myFileName, file.name(), sizeof(myFileName));

// modify it, reprint it, use in rename function..

Thank you very much.
This worked perfectly.

Sam :grinning: