-->
Page 3 of 3

Re: SPIFFS function fieStore -- file rename fails

PostPosted: Mon Mar 27, 2017 7:21 am
by martinayotte
In the above code, you are trying to rename the file before it is been closed.
As I said earlier, this produce a lock and the rename won't happen.
Reverse the order of those operation : close the file first and then rename it.

Re: SPIFFS function fieStore -- file rename fails

PostPosted: Mon Mar 27, 2017 1:34 pm
by Sirquil
Stripped everything excepting renaming code.

Code: Select allvoid fileStore()   //If 7th day of week, rename "log.txt" to ("log" + month + day + ".txt") and create new, empty "log.txt"
{

     getDateTime();
     
     
     // rename the file "LOG.TXT"
     String logname;
     logname = "LOG";
     logname += Clock.getMonth(Century);
     logname += Clock.getDate();
     logname += ".TXT";
     SPIFFS.rename("LOG.TXT", logname.c_str());
     
     //For troubleshooting
     Serial.println(logname.c_str());

}


Same result with stripped out code above; no "LOG325.TXT" listed by listFiles function. Serial Monitor shows the filename "LOG325.TXT."

What file are you seeing that is open?

William

Re: SPIFFS function fieStore -- file rename fails

PostPosted: Mon Mar 27, 2017 3:00 pm
by Sirquil
Thank you martinayotte!

I modified the stripped down code; to provide absolute path (root directory).

File was renamed, showing correctly in listFile function!

Code: Select all // rename the file "LOG.TXT"
     String logname;
     logname = "/LOG";
     logname += Clock.getMonth(Century);
     logname += Clock.getDate();
     logname += ".TXT";
     SPIFFS.rename("/LOG.TXT", logname.c_str());
     
     //For troubleshooting
     Serial.println(logname.c_str());


William