-->
Page 1 of 1

how to list all files in the spiffs file system.

PostPosted: Mon Feb 29, 2016 6:43 pm
by Mmiscool
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());
}

Re: how to list all files in the spiffs file system.

PostPosted: Tue Mar 01, 2016 9:27 am
by martinayotte
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);

Re: how to list all files in the spiffs file system.

PostPosted: Sun Jun 21, 2020 5:12 pm
by Kevin LaFarge
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)...

Re: how to list all files in the spiffs file system.

PostPosted: Tue Jun 30, 2020 12:46 pm
by DIRR70
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() {
}