Thank you J-M-L.
I didn't find useful info. of doc.
the test.txt is the code designed. and I added some thing like, and the code wait for type input that is a file listed.
while (Serial.available() == 0) {} //wait for data available
ReceiveName = Serial.readString();
ReceiveName.trim();
I don't know why not work.
Revised:
String ReceiveName;
#include "SPIFFS.h"
void listAllFiles() {
File root = SPIFFS.open("/");
File file = root.openNextFile();
while (file) {
Serial.print("FILE: ");
Serial.println(file.name());
file = root.openNextFile();
}
}
void setup() {
Serial.begin(115200);
if (!SPIFFS.begin(true)) {
Serial.println("An Error has occurred while mounting SPIFFS");
return;
}
File file = SPIFFS.open("/test.txt", FILE_WRITE);
if (!file) {
Serial.println("There was an error opening the file for writing");
return;
}
if (file.print("some content")) {
Serial.println("File was written");
} else {
Serial.println("File write failed");
}
file.close();
Serial.println("\n\n---BEFORE RENAMING---");
listAllFiles();
////////////////////////
while (Serial.available() == 0) {} //wait for data available
ReceiveName = Serial.readString();
ReceiveName.trim();
Serial.println("ReceiveName =");
Serial.println(ReceiveName);
////////////////////////
//// SPIFFS.rename("/test.txt", "/renamed.txt");
SPIFFS.rename(ReceiveName.c_str(), "/renamed.txt");
Serial.println("\n\n---AFTER RENAMING---");
listAllFiles();
}
void loop() {}