Directory object

In case you need to iterate on all the files from a directory you can use the Dir (Directory) object. There are three methods available to iterate next(), get the name of the next file file Name() and to open the directory openDir(mode):

SPIFFS doesn't support directories. In fact it produces a flat structure. Creating a file with path /data/log.txt will create a file called /data/log.txt instead of log.txt under the directory data.
Dir dir = SPIFFS.openDir("/data"); 
while (dir.next()) { 
    Serial.print(dir.fileName()); 
    File f = dir.openFile("r"); 
    Serial.println(f.size()); 
} 

From the preceding code we learn that:

  • mode from openDir can have the same values as the open function from the SPIFFS object
  • dir.next() returns true if there are files in the data directory and must be called before the fileName() and openFile(mode) functions
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.17.127