acid-drop- Hacking the planet from a LilyGo T-Deck using custom firmware |
git clone git://git.acid.vegas/acid-drop.git |
Log | Files | Refs | Archive | README | LICENSE |
SPIFFS_functions.ino (2444B)
1 /*==================================================================================== 2 This sketch supports for the ESP6266 and ESP32 SPIFFS filing system 3 4 Created by Bodmer 15th Jan 2017 5 ==================================================================================*/ 6 7 //==================================================================================== 8 // Print a SPIFFS directory list (root directory) 9 //==================================================================================== 10 11 void listFiles(void) { 12 Serial.println(); 13 Serial.println("SPIFFS files found:"); 14 15 #ifdef ESP32 16 listDir(SPIFFS, "/", true); 17 #else 18 fs::Dir dir = SPIFFS.openDir("/"); // Root directory 19 String line = "====================================="; 20 21 Serial.println(line); 22 Serial.println(" File name Size"); 23 Serial.println(line); 24 25 while (dir.next()) { 26 String fileName = dir.fileName(); 27 Serial.print(fileName); 28 int spaces = 25 - fileName.length(); // Tabulate nicely 29 if (spaces < 0) spaces = 1; 30 while (spaces--) Serial.print(" "); 31 fs::File f = dir.openFile("r"); 32 Serial.print(f.size()); Serial.println(" bytes"); 33 yield(); 34 } 35 36 Serial.println(line); 37 #endif 38 Serial.println(); 39 delay(1000); 40 } 41 //==================================================================================== 42 43 #ifdef ESP32 44 void listDir(fs::FS &fs, const char * dirname, uint8_t levels) { 45 Serial.printf("Listing directory: %s\n", dirname); 46 47 fs::File root = fs.open(dirname); 48 if (!root) { 49 Serial.println("Failed to open directory"); 50 return; 51 } 52 if (!root.isDirectory()) { 53 Serial.println("Not a directory"); 54 return; 55 } 56 57 fs::File file = root.openNextFile(); 58 while (file) { 59 60 if (file.isDirectory()) { 61 Serial.print("DIR : "); 62 String fileName = file.name(); 63 Serial.print(fileName); 64 if (levels) { 65 listDir(fs, file.name(), levels - 1); 66 } 67 } else { 68 String fileName = file.name(); 69 Serial.print(" " + fileName); 70 int spaces = 32 - fileName.length(); // Tabulate nicely 71 if (spaces < 1) spaces = 1; 72 while (spaces--) Serial.print(" "); 73 String fileSize = (String) file.size(); 74 spaces = 8 - fileSize.length(); // Tabulate nicely 75 if (spaces < 1) spaces = 1; 76 while (spaces--) Serial.print(" "); 77 Serial.println(fileSize + " bytes"); 78 } 79 80 file = root.openNextFile(); 81 } 82 } 83 #endif