Chat freely about anything...

User avatar
By Sirquil
#64236 If 7th day of week, rename "log.txt" to ("log" + month + day + ".txt") and create new, empty "log.txt"

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
     
     getDateTime();

     File log = SPIFFS.open("LOG.TXT", "a");

     if (!log)
     {
          Serial.println("file open failed");
     }

     // rename the file "LOG.TXT"
     
     logname = "";
     logname = "LOG";
     logname += Clock.getMonth(Century);
     logname += Clock.getDate();
     logname += ".TXT";
     
     Serial.println("Gets Here 2");

     //For troubleshooting
     //Serial.println(logname.c_str());

     log.close();

     // create a new "log.txt" file for appended writing
     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");

   
   

}



Putting Serial.println into function; function is completing without renaming the file.

William
User avatar
By Sirquil
#64245
Code: Select all     logname = "LOG";
     logname += Clock.getMonth(Century);
     logname += Clock.getDate();
     logname += ".TXT";
     SPIFFS.rename("LOG.TXT", logname.c_str());


Code produces filename in the format "LOGxxyy.TXT;" where xx is the month and yy is the date, this is correct. Problem is it does not rename the file.

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
     
     getDateTime();

     File log = SPIFFS.open("LOG.TXT", "a");

     if (!log)
     {
          Serial.println("file open failed");
     }

     // rename the file "LOG.TXT"
     
     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());

     log.close();

     // create a new "log.txt" file for appended writing
     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");

   
   

}


William