Timestamps are correct with this function.
Original library example function:
void listDir(const char * dirname) {
Serial.printf("Listing directory: %s\n", dirname);
Dir root = LittleFS.openDir(dirname);
while (root.next()) {
File file = root.openFile("r");
Serial.print(" FILE: ");
Serial.print(root.fileName());
Serial.print(" SIZE: ");
Serial.print(file.size());
time_t cr = file.getCreationTime();
time_t lw = file.getLastWrite();
file.close();
struct tm * tmstruct = localtime(&cr);
Serial.printf(" CREATION: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec);
tmstruct = localtime(&lw);
Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec);
}
}
Timestamps are wrong with this function.
New "listDel" function:
void listDel(const char * dirname) {
Serial.printf("Listing directory: %s\n", dirname);
Dir root = LittleFS.openDir("/");
while(root.next())
{
File file = root.openFile("r");
String str = root.fileName();
i++;
filelist[i] = strdup(str.c_str());
Serial.print(filelist[i]);
Serial.print(" ");
Serial.print(i);
Serial.println("");
file = file.openNextFile();
time_t cr = file.getCreationTime();
time_t lw = file.getLastWrite();
file.close();
struct tm * tmstruct = localtime(&cr);
Serial.printf(" CREATION: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec);
tmstruct = localtime(&lw);
Serial.printf(" LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct->tm_year) + 1900, (tmstruct->tm_mon) + 1, tmstruct->tm_mday, tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec);
}
for(i = 1;i < 5; i++) //Delete only first four files; keep from getting too many log files.
{
LittleFS.remove("/" + String(filelist[i]));
Serial.print("Removed: ");
Serial.print(filelist[i]);
Serial.print(" ");
Serial.print(i);
Serial.println("");
}
i = 0;
}
Why do I have wrong Timestamp using "listDel" instead of "listDir?"
Attached modified library example uses a modified "ESP8266FtpServer.cpp for use with "LittleFS."
"LittleFS" is the replacement for "SPIFFS."
Purpose of "listDel" function is put filenames into an array; then to delete the first four files.
William
Attachments
(2.09 KiB) Downloaded 250 times