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.ino (2579B)

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