You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
740 B

  1. #include "fsutils.h"
  2. void dir_list(fs::FS &fs, const char * dirname, uint8_t levels)
  3. {
  4. Serial.printf("Listing directory: %s\n", dirname);
  5. File root = fs.open(dirname);
  6. if(!root){
  7. Serial.println("Failed to open directory");
  8. return;
  9. }
  10. if(!root.isDirectory()){
  11. Serial.println("Not a directory");
  12. return;
  13. }
  14. File file = root.openNextFile();
  15. while(file){
  16. if(file.isDirectory()){
  17. Serial.print(" DIR : ");
  18. Serial.println(file.name());
  19. if(levels){
  20. dir_list(fs, file.name(), levels -1);
  21. }
  22. } else {
  23. Serial.print(" FILE: ");
  24. Serial.print(file.name());
  25. Serial.print(" SIZE: ");
  26. Serial.println(file.size());
  27. }
  28. file = root.openNextFile();
  29. }
  30. }