This commit is contained in:
pgp 2021-04-16 11:17:21 +02:00
parent b4196e696c
commit 0c33b024e4

View file

@ -211,6 +211,55 @@ void compte_tour() {
/// FONCTIONS SD CARD /// /// FONCTIONS SD CARD ///
///////////////////////// /////////////////////////
void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
Serial.printf("Listing directory: %s\n", dirname);
File root = fs.open(dirname);
if(!root){
Serial.println("Failed to open directory");
return;
}
if(!root.isDirectory()){
Serial.println("Not a directory");
return;
}
File file = root.openNextFile();
while(file){
if(file.isDirectory()){
Serial.print(" DIR : ");
Serial.println(file.name());
if(levels){
listDir(fs, file.name(), levels -1);
}
} else {
Serial.print(" FILE: ");
Serial.print(file.name());
Serial.print(" SIZE: ");
Serial.println(file.size());
}
file = root.openNextFile();
}
}
void createDir(fs::FS &fs, const char * path){
Serial.printf("Creating Dir: %s\n", path);
if(fs.mkdir(path)){
Serial.println("Dir created");
} else {
Serial.println("mkdir failed");
}
}
void removeDir(fs::FS &fs, const char * path){
Serial.printf("Removing Dir: %s\n", path);
if(fs.rmdir(path)){
Serial.println("Dir removed");
} else {noreply@dutchorange.org
Serial.println("rmdir failed");
}
}
void readFile(fs::FS &fs, const char * path){ void readFile(fs::FS &fs, const char * path){
Serial.printf("Reading file: %s\n", path); Serial.printf("Reading file: %s\n", path);
@ -260,6 +309,15 @@ void appendFile(fs::FS &fs, const char * path, const char * message){
file.close(); file.close();
} }
void renameFile(fs::FS &fs, const char * path1, const char * path2){
Serial.printf("Renaming file %s to %s\n", path1, path2);
if (fs.rename(path1, path2)) {
Serial.println("File renamed");
} else {
Serial.println("Rename failed");
}
}
void deleteFile(fs::FS &fs, const char * path){ void deleteFile(fs::FS &fs, const char * path){
Serial.printf("Deleting file: %s\n", path); Serial.printf("Deleting file: %s\n", path);
if(fs.remove(path)){ if(fs.remove(path)){