Re: SPIFFS function fieStore -- file rename fails
Posted:
Sun Mar 26, 2017 4:11 pm
by martinayotte
I've just tested the SPIFFS.rename() and it is working properly.
Maybe something else in your code that you didn't tested properly.
Re: SPIFFS function fieStore -- file rename fails
Posted:
Sun Mar 26, 2017 5:01 pm
by Sirquil
I've just tested the SPIFFS.rename() and it is working properly.
Maybe something else in your code that you didn't tested properly. - See more at: posting.php?mode=reply&f=6&t=14299#sthash.w2e538AQ.dpuf
I do not understand; when I list the files with listFile function, the renamed file is not listed.
Serial.println(logname.c_str() prints the String filename. Filename produced is "LOG325.TXT" is correct for month and date.
William
Re: SPIFFS function fieStore -- file rename fails
Posted:
Sun Mar 26, 2017 5:21 pm
by martinayotte
Oh ! I figured out something looking at your code :
You open the file before renaming it, it should not be open !
It is a bit like the file becomes locked, and rename() probably fail because of that.
Why do you need to open it ? Simply rename it, and then open the renamed version ...
(If you open it, just to write something into it, do the writes, then close it and then rename it
Re: SPIFFS function fieStore -- file rename fails
Posted:
Sun Mar 26, 2017 7:36 pm
by Sirquil
Removed the File log open and close; same result, "LOG325.TXT" is not listed by listFile function.
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());
Serial.println("Gets Here 2");
//For troubleshooting
Serial.println(logname.c_str());
// create a new "log.txt" file for appended writing
File log = SPIFFS.open("LOG.TXT", "a");
if (!log)
{
Serial.println("file open failed");
}
log.println("");
log.close();
Serial.println("");
Serial.println("New LOG.TXT created");
}
This is the function fileStore from the Arduino Mega 2560 that worked:
Code: Select allvoid fileStore() //If 7th day of week, rename "log.txt" to ("log" + month + day + ".txt") and create new, empty "log.txt"
{
// create a file and write one line to the file
SdFile logFile("log.txt", O_WRITE | O_CREAT );
if (!logFile.isOpen())
{
error("log.txt --new -open");
}
// rename the file log.txt
// sd.vwd() is the volume working directory, root.
logFileName = "";
logFileName = "log";
logFileName += (RTCTimedEvent.time.month);
logFileName += (RTCTimedEvent.time.day);
logFileName += ".txt";
//Serial.println(logFileName.c_str());
if(sd.exists("log.txt"))
{
logFile.rename(sd.vwd(), logFileName.c_str());
logFile.close();
}
else
{
exit;
}
// create a new "log.txt" file for appended writing
logFile.open("log.txt", O_WRITE | O_CREAT | O_APPEND);
logFile.println("");
logFile.close();
Serial.begin(115200);
Serial.println("");
Serial.println("New LOG.TXT created");
// list files
cout << pstr("------") << endl;
sd.ls(LS_R);
Serial.flush();
Serial.end();
}
William