SPIFFS_Support.ino 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*====================================================================================
  2. This sketch contains support functions for the ESP6266 SPIFFS filing system
  3. Created by Bodmer 15th Jan 2017
  4. ==================================================================================*/
  5. //====================================================================================
  6. // Print a SPIFFS directory list (root directory)
  7. //====================================================================================
  8. void listFiles(void) {
  9. Serial.println();
  10. Serial.println("SPIFFS files found:");
  11. fs::Dir dir = SPIFFS.openDir(""); // Root directory
  12. String line = "=====================================";
  13. uint32_t totalBytes = 0;
  14. Serial.println(line);
  15. Serial.println(" File name Size");
  16. Serial.println(line);
  17. while (dir.next()) {
  18. String fileName = dir.fileName();
  19. Serial.print(fileName);
  20. int spaces = 25 - fileName.length(); // Tabulate nicely
  21. while (spaces--) Serial.print(" ");
  22. fs::File f = dir.openFile("r");
  23. Serial.print(f.size()); Serial.println(" bytes");
  24. totalBytes += f.size();
  25. }
  26. Serial.println(); Serial.print("Total = ");
  27. int spaces = 25 - 8; // Tabulate nicely
  28. while (spaces--) Serial.print(" ");
  29. Serial.print(totalBytes); Serial.println(" bytes");
  30. Serial.println(line);
  31. Serial.println();
  32. delay(1000);
  33. }
  34. //====================================================================================