Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By Mmiscool
#42128 How can I list all of the files in the spiffs file system.

I tried the following code. Is there a simple way to list all files stored in spiffs?

Code: Select allDir dir = SPIFFS.openDir("");
while (dir.next()) {
    Serial.print(dir.fileName());
    File f = dir.openFile("r");
    Serial.println(f.size());
}
User avatar
By martinayotte
#42161 Hi Michael,

You don't need to openFile to get its size, the Dir object provides fileSize() function :

Code: Select allString str = "";
Dir dir = SPIFFS.openDir("/");
while (dir.next()) {
    str += dir.fileName();
    str += " / ";
    str += dir.fileSize();
    str += "\r\n";
}
Serial.print(str);
User avatar
By Kevin LaFarge
#87608
Mmiscool wrote:How can I list all of the files in the spiffs file system.

I tried the following code. Is there a simple way to list all files stored in spiffs?

Code: Select allDir dir = SPIFFS.openDir("");
while (dir.next()) {
    Serial.print(dir.fileName());
    File f = dir.openFile("r");
    Serial.println(f.size());
}


If all I wanted to do was read all the files on the esp8266 file system, could you post a simple sketch to do so? (currently banging my face against my desk, wasting days at a time trying to learn this stuff)...
User avatar
By DIRR70
#87718 Hi Kevin,

Assuming you really already have files on your SPIFFS (here is a good explanation how to upload files: https://randomnerdtutorials.com/install-esp8266-filesystem-uploader-arduino-ide ) that would be your code:
Code: Select all#include "FS.h"

void setup() {
  Serial.begin (115200);

  if (!SPIFFS.begin ()) {
    Serial.println ("An Error has occurred while mounting SPIFFS");
    return;
  }

  Dir dir = SPIFFS.openDir ("");
  while (dir.next ()) {
    Serial.println (dir.fileName ());
    Serial.println (dir.fileSize ());
  }
}

void loop() {
}