LittleFS recursive display and erase. Cause we got directories now, baby!

This commit is contained in:
Thomas Göttgens
2022-03-15 22:22:05 +01:00
parent b9058ce7c5
commit 697c749a8d
2 changed files with 124 additions and 76 deletions

View File

@@ -1,22 +1,43 @@
#include "configuration.h"
#include "FSCommon.h"
void listDir(fs::FS &fs, const char * dirname, uint8_t levels)
#ifdef FSCom
{
File root = fs.open(dirname);
if(!root){
return;
}
if(!root.isDirectory()){
return;
}
File file = root.openNextFile();
while(file){
if(file.isDirectory()){
if(levels){
listDir(fs, file.name(), levels -1);
}
} else {
DEBUG_MSG(" %s (%i Bytes)\n", file.name(), file.size());
}
file.close();
file = root.openNextFile();
}
file.close();
#endif
}
void fsInit()
{
#ifdef FSCom
if (!FSBegin())
{
DEBUG_MSG("ERROR filesystem mount Failed\n");
DEBUG_MSG("ERROR filesystem mount Failed. Formatting...\n");
assert(0); // FIXME - report failure to phone
}
DEBUG_MSG("Filesystem files:\n");
File dir = FSCom.open("/");
File f = dir.openNextFile();
while (f) {
DEBUG_MSG(" %s\n", f.name());
f.close();
f = dir.openNextFile();
}
listDir(FSCom, "/", 10);
#endif
}