How to check if it is a directory?

I rewrote it, check this out:

/*
 * Connect the SD card to the following pins:
 *
 * SD Card | ESP32
 *    D2       -
 *    D3       SS
 *    CMD      MOSI
 *    VSS      GND
 *    VDD      3.3V
 *    CLK      SCK
 *    VSS      GND
 *    D0       MISO
 *    D1       -
 */
#include "FS.h"
#include "SD.h"
#include "SPI.h"

struct sizeType {
   unsigned long local    = 0;
   unsigned long complete = 0;
};

String target_path = "/";

sizeType getDirSize(fs::FS &fs, const char * dirname){
  sizeType dirSize;
  sizeType gotSize;
    File root = fs.open(dirname);
    if(!root){
        Serial.println("Failed to open directory");
        return dirSize;
    }
    if(!root.isDirectory()){
        Serial.println("Not a directory");
        return dirSize;
    }

    File file = root.openNextFile();
    while(file){
        if(!file.isDirectory()){
            dirSize.local += file.size();
            dirSize.complete += file.size();
        } else {
            gotSize = getDirSize(fs,file.path());
            dirSize.complete += gotSize.complete;         
        }
        file = root.openNextFile();
    }
    return dirSize;
}


void listDir(fs::FS &fs, const char * dirname, uint8_t level){
    sizeType dirSize = getDirSize(fs, dirname);
    Serial.println("-----------------------------------------------------");
    Serial.printf("DIR : %-28s %10d\n",dirname, dirSize.local);

    File root = fs.open(dirname);
    if(!root){
        Serial.println("Failed to open directory");
        return;
    }
    if(!root.isDirectory()){
        Serial.println("Not a directory");
        return;
    }

    File file = root.openNextFile();
    while(file){
        if(!file.isDirectory()){
           Serial.printf("FILE: %-36s %10d\n", file.name(), file.size());
        }
        file = root.openNextFile();
    }
    root = fs.open(dirname);
    file = root.openNextFile();
    while(file){
        if(file.isDirectory()){
          listDir(fs, file.path(), level+1);
        }  
        file = root.openNextFile();
    }
    if (level == 0){
      Serial.println("=====================================================");
      Serial.println("TOTAL SIZE:  "+String(dirSize.complete));
      Serial.println("=====================================================");
    }
}


void setup(){
    Serial.begin(115200);
    if(!SD.begin()){
        Serial.println("Card Mount Failed");
        return;
    }
    uint8_t cardType = SD.cardType();

    if(cardType == CARD_NONE){
        Serial.println("No SD card attached");
        return;
    }

    Serial.print("SD Card Type: ");
    if(cardType == CARD_MMC){
        Serial.println("MMC");
    } else if(cardType == CARD_SD){
        Serial.println("SDSC");
    } else if(cardType == CARD_SDHC){
        Serial.println("SDHC");
    } else {
        Serial.println("UNKNOWN");
    }

    uint64_t cardSize = SD.cardSize() / (1024 * 1024);
    Serial.printf("SD Card Size: %lluMB\n", cardSize);

    listDir(SD, "/", 0);
}

void loop(){

}

Example Output:

SD Card Type: SDSC
SD Card Size: 974MB
-----------------------------------------------------
DIR : /                               1051308
FILE: test.txt                                1048576
FILE: foo.txt                                      13
FILE: 1.txt                                      2719
-----------------------------------------------------
DIR : /System Volume Information           88
FILE: WPSettings.dat                               12
FILE: IndexerVolumeGuid                            76
-----------------------------------------------------
DIR : /dir1                              6357
FILE: 2.txt                                      2770
FILE: 5.txt                                      3587
-----------------------------------------------------
DIR : /dir1/dir2                         6574
FILE: 3.txt                                      3287
FILE: 4.txt                                      3287
=====================================================
TOTAL SIZE:  1064327
=====================================================

Uses

#include "FS.h"
#include "SD.h"
#include "SPI.h"

and works fine with ESP32 (if the SD card is properly formatted).

The "trick" is to first process files only and in a second while() the directories ....

1 Like

Interesting code and beautiful result. Unfortunately today I will hardly have time to try to remake the code for ESP32 without a sd card, because there is no sd card. But anyway, I have a few questions:

  1. Since I'm a beginner, I don't quite understand what a "struct" is. Could you briefly explain in your own words what it is and give a link where, in your opinion, it is popularly described?
  2. In the so-called "original" and you use if(!root) and if(!root.isDirectory() but I do not quite understand what this gives, especially considering that these are two "if" in a row. I I tried to replace it with "else if" but apparently it doesn't work, or I'm checking it wrong, not understanding what exactly is checked by this.
  3. Again, I do not understand the use of "return" ... Especially since it seemed to me that after "return" the function should generally be interrupted, returning the result. But it continues and code like File file = root.openNextFile();

Of course, I will try to redo the code for ESP32 and LittleFS today, but I'm not sure if I can do it

I tried to change it. For some reason, I'm swearing at this line. Here's an error:

error: format '%d' expects argument of type 'int', but argument 4 has type 'long unsigned int' [-Werror=format=]
     Serial.printf("DIR : %-28s %10d\n",dirname, dirSize.local);
                   ^~~~~~~~~~~~~~~~~~~~          ~~~~~~~~~~~~~
cc1plus.exe: some warnings being treated as errors

For the sake of interest, I wrote 0 there, compiled and, in principle, it turned out not bad, except for the zeros in the directory size. But the total amount was calculated correctly this time.

-----------------------------------------------------
DIR : /                                     0
FILE: Arakona.jpg                               65047
FILE: Egipt_08.jpg                              18031
FILE: Test3.txt                                     0
FILE: fish10.jpg                                18883
FILE: ignore.txt                                    0
FILE: index.htm                                   451
-----------------------------------------------------
DIR : /edit                                 0
FILE: index.htm                                 40877
-----------------------------------------------------
DIR : /kat01                                0
-----------------------------------------------------
DIR : /kat1                                 0
FILE: kat11.txt                                     0
FILE: buhta.jpg                            67589
-----------------------------------------------------
DIR : /kat1/kat11                           0
-----------------------------------------------------
DIR : /mydir                                0
FILE: Test2.txt                                    14
=====================================================
TOTAL SIZE:  210892
=====================================================

Other changes are also minimal. I just removed the restriction on the depth of scanning and work with maps. Why swears at a different data type, I can’t understand

I have never done this before, and to be honest, I still don’t know what kind of method it is to print information like this, but I found an example on the Internet with correcting a similar error and everything worked out. Did it like this:

Serial.printf("DIR : %-28s %10lu\n",dirname, dirSize.local);

Received:

-----------------------------------------------------
DIR : /                                102412
FILE: Arakona.jpg                               65047
FILE: Egipt_08.jpg                              18031
FILE: Test3.txt                                     0
FILE: fish10.jpg                                18883
FILE: ignore.txt                                    0
FILE: index.htm                                   451
-----------------------------------------------------
DIR : /edit                             40877
FILE: index.htm                                 40877
-----------------------------------------------------
DIR : /kat01                                0
-----------------------------------------------------
DIR : /kat1                             67589
FILE: kat11.txt                                     0
FILE: buhta.jpg                            67589
-----------------------------------------------------
DIR : /kat1/kat11                           0
-----------------------------------------------------
DIR : /mydir                               14
FILE: Test2.txt                                    14
=====================================================
TOTAL SIZE:  210892
=====================================================

It actually turned out to be easier than I thought. Even got it done today. Here is the code:

#include <LittleFS.h>

struct sizeType {
   unsigned long local    = 0;
   unsigned long complete = 0;
};

const char * target_path = "/";

sizeType getDirSize(const char * path){
  sizeType dirSize;
  sizeType gotSize;
    File root = LittleFS.open(path);
    if(!root){
        Serial.println("Failed to open directory");
        return dirSize;
    }
    if(!root.isDirectory()){
        Serial.println("Not a directory");
        return dirSize;
    }

    File file = root.openNextFile();
    while(file){
        if(!file.isDirectory()){
            dirSize.local += file.size();
            dirSize.complete += file.size();
        } else {
            gotSize = getDirSize(file.path());
            dirSize.complete += gotSize.complete;         
        }
        file = root.openNextFile();
    }
    return dirSize;
}


void listDir(const char * path, boolean isFirstDir){
    sizeType dirSize = getDirSize(path);
    Serial.println("-----------------------------------------------------");
    Serial.printf("DIR : %-28s %10lu\n",path, dirSize.local);

    File root = LittleFS.open(path);
    if(!root){
        Serial.println("Failed to open directory");
        return;
    }
    if(!root.isDirectory()){
        Serial.println("Not a directory");
        return;
    }

    File file = root.openNextFile();
    while(file){
        if(!file.isDirectory()){
           Serial.printf("FILE: %-36s %10d\n", file.name(), file.size());
        }
        file = root.openNextFile();
    }
    root = LittleFS.open(path);
    file = root.openNextFile();
    while(file){
        if(file.isDirectory()){
          listDir(file.path(), false);
        }  
        file = root.openNextFile();
    }
if (isFirstDir){
      Serial.println("=====================================================");
      Serial.println("TOTAL SIZE:  "+String(dirSize.complete));
      Serial.println("=====================================================");
      }
}


void setup(){
    Serial.begin(115200);
    if(!LittleFS.begin()){
        Serial.println("LittleFS Mount Failed");
        return;
    }

    listDir(target_path, true);
}

void loop(){

}

Here is the output to the serial port:

-----------------------------------------------------
DIR : /                                102412
FILE: Arakona.jpg                               65047
FILE: Egipt_08.jpg                              18031
FILE: Test3.txt                                     0
FILE: fish10.jpg                                18883
FILE: ignore.txt                                    0
FILE: index.htm                                   451
-----------------------------------------------------
DIR : /edit                             40877
FILE: index.htm                                 40877
-----------------------------------------------------
DIR : /kat01                                0
-----------------------------------------------------
DIR : /kat1                             67589
FILE: kat11.txt                                     0
FILE: buhta.jpg                            67589
-----------------------------------------------------
DIR : /kat1/kat11                           0
-----------------------------------------------------
DIR : /mydir                               14
FILE: Test2.txt                                    14
=====================================================
TOTAL SIZE:  210892
=====================================================

Now I can think about combining the sketch so that it works for LittleFs and for SD cards. I don't want to do it under SPIFFS either. Even I managed to notice the problems that arise with it.
And I can try to combine the sketch for esp8266 and for esp32.
But those three questions that I voiced above still interest me.

Question 1: I have written an introduction how to use structs and from struct to class, will deploy this in the forum and provide the link when it is done.

See here:

https://forum.arduino.cc/t/proposal-for-tutorial-use-of-array-struct-and-class-to-handle-several-actuators-in-one-sketch/1114824

Question 2:

I assume you refer to this:

 File root = fs.open(dirname);
    if(!root){
        Serial.println("Failed to open directory");
        return dirSize;
    }
    if(!root.isDirectory()){
        Serial.println("Not a directory");
        return dirSize;
    }

The line

File root = fs.open(dirname);

returns 0 (zero) if the call was not successful. As zero equals false the term

!root

returns true (! means not and inverts the boolean state).

So if root was not created successfully the error is printed and the function immediately returns to the line where it was called from.

This applies similar to if the path opened was a file and not a directory.

Question 3: The "return dirSize" is after the closing bracket of the while() loop.

1 Like

I have found time again to work on Arduino. It's difficult to remember what I did before, but unfortunately, either I didn't save the working version or I never made a version for ESP8266. I'm now trying to recall and modify this example according to the specifications for ESP8266.
It looks like this:

#include <LittleFS.h>

struct sizeType {
   unsigned long local    = 0;
   unsigned long complete = 0;
};

const char * target_path = "/";

sizeType getDirSize(const char * path){
  sizeType dirSize;
  sizeType gotSize;
    Dir root = LittleFS.openDir(path);
    if(!root){
        Serial.println("Failed to open directory");
        return dirSize;
    }
    if(!root.isDirectory()){
        Serial.println("Not a directory");
        return dirSize;
    }

    File file = root.openNextFile();
    while(file){
        if(!file.isDirectory()){
            dirSize.local += file.size();
            dirSize.complete += file.size();
        } else {
            gotSize = getDirSize(file.path());
            dirSize.complete += gotSize.complete;         
        }
        file = root.openNextFile();
    }
    return dirSize;
}


void listDir(const char * path, boolean isFirstDir){
    sizeType dirSize = getDirSize(path);
    Serial.println("-----------------------------------------------------");
    Serial.printf("DIR : %-28s %10lu\n",path, dirSize.local);

    Dir root = LittleFS.openDir(path);
    if(!root){
        Serial.println("Failed to open directory");
        return;
    }
    if(!root.isDirectory()){
        Serial.println("Not a directory");
        return;
    }

    File file = root.openNextFile();
    while(file){
        if(!file.isDirectory()){
           Serial.printf("FILE: %-36s %10d\n", file.name(), file.size());
        }
        file = root.openNextFile();
    }
    root = LittleFS.openDir(path);
    file = root.openNextFile();
    while(file){
        if(file.isDirectory()){
          listDir(file.path(), false);
        }  
        file = root.openNextFile();
    }
if (isFirstDir){
      Serial.println("=====================================================");
      Serial.println("TOTAL SIZE:  "+String(dirSize.complete));
      Serial.println("=====================================================");
      }
}


void setup(){
    Serial.begin(74880);
    if(!LittleFS.begin()){
        Serial.println("LittleFS Mount Failed");
        return;
    }

    listDir(target_path, true);
}

void loop(){

}

However, I'm encountering an error:

14:8: error: no match for 'operator!' (operand type is 'fs::Dir')

There are other errors as well, but it seems that all the errors are related to this one. It's strange that a simple check like this is causing such an error. Out of curiosity, I tried a similar approach in one of the saved versions

void scan_dir(String path) {
  Dir dir1 = LittleFS.openDir(path);
  while (dir1.next()) {
      if (!dir1.isDirectory()){
//      if (dir1.isFile()){        
        Serial.print("File:\t");
        Serial.print(path + dir1.fileName());
        Serial.print("\tSize:\t");
        Serial.println(dir1.fileSize());
      }
      if (dir1.isDirectory()) {
        Serial.print("Dir:\t");
        Serial.print(path+dir1.fileName()+"/");
        Serial.print("\t\tSize:\t");
        Serial.println(dirSize(path+dir1.fileName()+"/"));        
        scan_dir(path+dir1.fileName()+"/"); //  Вызов рекурсии
      }
  }
}

And it works. Can you tell me where this error for evp8266 comes from?

The error message tells that the operator ! (not operator ) is not defined for the datatype of "fs::Dir".

In the function scan_dir() you do not use the ! operator with the variable dir1 (but with the function dir1.isDirectory() which returns a boolean value). That would explain why you do not get the same error message.

You may try to find out what datatype fs::Dir is, I guess it may be a pointer. Then it depends whether the function call

Dir root = LittleFS.openDir(path);

returns a simple zero or the NULL pointer when path is not existing ...

Instead of

if (!root) {

you can try these alternatives

if (root == 0) {

or

if (root == NULL) {

If you get an error message that NULL is not defined you may try to include

#include <Arduino.h>

or

#include <stddef.h>

Good luck!

Unfortunately, this advice didn't help. I reworked the code differently. And frankly, I don't understand why for ESP32 there is no need to add an operator/modulator when opening a file. Additionally, I added a check for the existence of the directory. In my opinion, it makes the reason more understandable in case there is an error running the sketch. Also, I managed to modify the output of the directory name for ESP8266. Now it is complete. Honestly, it didn't work with a short name. And perhaps now it has become more visually clear. I haven't been able to do this for ESP32 yet. Nevertheless, after taking a closer look at the results of calculating the directory size, although it provides the correct result for the root directory, there is still an error when calculating the size of nested directories. Specifically, it only considers the overall size of files. But if there is a nested directory, that directory is not taken into account. Unfortunately, I haven't solved this problem yet.
Here is what the code looks like for ESP8266 now.

#include <LittleFS.h>

String name_file = "scan_8266_new_1";

struct sizeType {
   unsigned long local    = 0;
   unsigned long complete = 0;
};

const char * target_path = "/";

void setup() {
  Serial.begin(74880);
  Serial.println("Sketch name is "+name_file);
  if(!LittleFS.begin()){
    delay(1000);
    Serial.println("LittleFS Mount Failed");
    return;
  } else {
    delay(1000);
    Serial.println("LittleFS Initialised OK");
  }
    listDir(target_path, true);
}

void loop(){

}

sizeType getDirSize(const char * path){
  sizeType dirSize;
  sizeType gotSize;
    File root = LittleFS.open(path, "r");
    if(!root){
        Serial.println("Failed to open directory");
        return dirSize;
    }
    if(!root.isDirectory()){
        Serial.println("Not a directory");
        return dirSize;
    }

    File file = root.openNextFile();
    while(file){
        if(!file.isDirectory()){
            dirSize.local += file.size();
            dirSize.complete += file.size();
        } else {
            gotSize = getDirSize(file.fullName());
            dirSize.complete += gotSize.complete;         
        }
        file = root.openNextFile();
    }
    return dirSize;
}

void listDir(const char * path, boolean isFirstDir){
  sizeType dirSize = getDirSize(path);
  Serial.println("-----------------------------------------------------");

  if(LittleFS.exists(path)){
    File root = LittleFS.open(path,"r");
    if(!root){
        Serial.println(String(path)+" Failed to open this directory");
        return;
    }
    if(!root.isDirectory()){
        Serial.println(String(path)+" Not a directory");
        return;
    }
  } else {
    Serial.println(String(path)+" Not exist");
    return;
  }
  Serial.printf("DIR : %-28s %10lu\n",path, dirSize.local);
  
    File root = LittleFS.open(path,"r");
    File file = root.openNextFile();
    while(file){
        if(!file.isDirectory()){
           Serial.printf("FILE: %-36s %10d\n", file.name(), file.size());
        }
        file = root.openNextFile();
    }
    root = LittleFS.open(path,"r");
    file = root.openNextFile();
    while(file){
        if(file.isDirectory()){
          listDir(file.fullName(), false);
        }  
        file = root.openNextFile();
    }
if (isFirstDir){
      Serial.println("=====================================================");
      Serial.println("TOTAL SIZE:  "+String(dirSize.complete));
      Serial.println("=====================================================");
      }
}

Here is what the result looks like.

LittleFS Initialised OK
-----------------------------------------------------
DIR : /                                 92587
FILE: Egipt_08.zip                              17688
FILE: favicon.ico                                1150
FILE: fish10.7z                                 17557
FILE: index.htm                                   451
FILE: pins.png                                  55578
FILE: unknown.abrval                              163
-----------------------------------------------------
DIR : edit                              40877
FILE: index.htm                                 40877
-----------------------------------------------------
DIR : edit/kat11                            0
-----------------------------------------------------
DIR : edit/kat11/kat21                      0
-----------------------------------------------------
DIR : edit/kat12                            0
-----------------------------------------------------
DIR : root_kat                              0
=====================================================
TOTAL SIZE:  133464
=====================================================

In theory, the root directory should have been equal to 92587 + 40877 = 133464, which is the same as the overall result because it has a nested directory called "edit" that also contains files. The same problem exists in the ESP32 variant as well.

In your example, it's the same. The directory dir1 contains the directory dir2, but it only shows the sum of the files without including the dir2 directory.
I wouldn't say it's a big problem. At least it's not immediately noticeable. But it would be nice to have a more accurate picture. Perhaps in the format: total files + total directories.

I understand that the sizes in general are ok but you would like a different way of summing-up, correct?

The way it is programmed shows the file sizes in each directory (without their sub dirs) and finally sums all file sizes up to total.

However you want to see the size of the files and its sub dirs summed up on each dir level, is that correct?

Yes, I'm still thinking about it. Of course, I won't refuse a hint.))) In your opinion, is such a calculation of the total sum reasonable, or is it unnecessary?

Reasonable or not depends on your objective ... :wink:

Based on the sketch from post 41 I have made some little changes so that the sum is also printed, but sorted in the same way as the iteration comes back from "deeper" dir levels (recursive):

/*
       Works with ESP32
 */
#include "FS.h"
#include "SD.h"
#include "SPI.h"

struct sizeType {
   unsigned long local    = 0;
   unsigned long complete = 0;
};

String target_path = "/";

sizeType getDirSize(fs::FS &fs, const char * dirname){
  sizeType dirSize;
  sizeType gotSize;
    File root = fs.open(dirname);
    if(!root){
        Serial.println("Failed to open directory");
        return dirSize;
    }
    if(!root.isDirectory()){
        Serial.println("Not a directory");
        return dirSize;
    }

    File file = root.openNextFile();
    while(file){
        if(!file.isDirectory()){
            dirSize.local += file.size();
            dirSize.complete += file.size();
        } else {
            gotSize = getDirSize(fs,file.path());
            dirSize.complete += gotSize.complete;         
        }
        file = root.openNextFile();
    }
    return dirSize;
}


void listDir(fs::FS &fs, const char * dirname, uint8_t level){
    boolean hasSubs = false;
    sizeType dirSize = getDirSize(fs, dirname);
    Serial.println("------------------- LOCAL FILES ---------------------");
    Serial.printf("DIR : %-28s %10d\n",dirname, dirSize.local);

    File root = fs.open(dirname);
    if(!root){
        Serial.println("Failed to open directory");
        return;
    }
    if(!root.isDirectory()){
        Serial.println("Not a directory");
        return;
    }

    File file = root.openNextFile();
    while(file){
        if(!file.isDirectory()){
           Serial.printf("FILE: %-36s %10d\n", file.name(), file.size());
        }
        file = root.openNextFile();
    }
    root = fs.open(dirname);
    file = root.openNextFile();
    while(file){
        if(file.isDirectory()){
          hasSubs = true;
          listDir(fs, file.path(), level+1);
        }  
        file = root.openNextFile();
    }
    if (level == 0 || hasSubs){
      Serial.println("=============== SIZE INCL. SUBDIRS ==================");
      Serial.printf("DIR : %-28s %10d\n",dirname, dirSize.complete);
      Serial.println("=====================================================");
    }
}


void setup(){
    Serial.begin(115200);
    if(!SD.begin()){
        Serial.println("Card Mount Failed");
        return;
    }
    uint8_t cardType = SD.cardType();

    if(cardType == CARD_NONE){
        Serial.println("No SD card attached");
        return;
    }

    Serial.print("SD Card Type: ");
    if(cardType == CARD_MMC){
        Serial.println("MMC");
    } else if(cardType == CARD_SD){
        Serial.println("SDSC");
    } else if(cardType == CARD_SDHC){
        Serial.println("SDHC");
    } else {
        Serial.println("UNKNOWN");
    }

    uint64_t cardSize = SD.cardSize() / (1024 * 1024);
    Serial.printf("SD Card Size: %lluMB\n", cardSize);

    listDir(SD, "/", 0);
}

void loop(){

}

Should be not to complicated for you to identify the changes in lisDir() and add them to your sketch. It is mainly a boolean that is set to true if the recent directory has sub dirs and that leads to a print of the "SIZE INCL. SUBDIRS" in case it has. This size should represent all files on the directory level and below. It won't come at the beginning of the print (as it is not known at that time due to the recursive function!)

Example print:

DIR : /dir1/dir1.1                       6574
FILE: 3.txt                                      3287
FILE: 4.txt                                      3287
=============== SIZE INCL. SUBDIRS ==================
DIR : /dir1                             12931
=====================================================
------------------- LOCAL FILES ---------------------
DIR : /dir2                                13
FILE: foo.txt                                      13
------------------- LOCAL FILES ---------------------
DIR : /dir2/dir2.1                       6357
FILE: 2.txt                                      2770
FILE: 5.txt                                      3587
------------------- LOCAL FILES ---------------------
DIR : /dir2/dir2.1/dir2.1.1              6574
FILE: 3.txt                                      3287
FILE: 4.txt                                      3287
=============== SIZE INCL. SUBDIRS ==================
DIR : /dir2/dir2.1                      12931
=====================================================
------------------- LOCAL FILES ---------------------
DIR : /dir2/dir2.2                       6357
FILE: 2.txt                                      2770
FILE: 5.txt                                      3587
------------------- LOCAL FILES ---------------------
DIR : /dir2/dir2.2/dir2.2.1              6574
FILE: 3.txt                                      3287
FILE: 4.txt                                      3287
=============== SIZE INCL. SUBDIRS ==================
DIR : /dir2/dir2.2                      12931
=====================================================
=============== SIZE INCL. SUBDIRS ==================
DIR : /dir2                             25875
=====================================================
=============== SIZE INCL. SUBDIRS ==================
DIR : /                               1090202
=====================================================
1 Like

For ESP32 I have already redone it, I got the same result as yours. I hope that I understand the principle and can slightly change the output of information about subdirectories. And then I will do for ESP8266.

Hi, I use platform.io with:

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
board_build.filesystem = littlefs
lib_deps = LittleFS @ ^2.0.0
bblanchon/ArduinoJson@^6.21.2
monitor_speed = 115200

But on compilation it gives this error:
class "fs::File" has no member "fullName"

The include i use:
#include <LittleFS.h>

Is there a library missing?

Are you using this sketch for ESP32? This is an example for ESP8266. They are slightly different. Usually people say in which line the error is, so that it is easier to understand where the problem is. Unfortunately, I don't know where in Platformio it shows the line that has an error.

I don't know the method "file.fullName()" in the two lines, in the respective example code.

I told you, there are differences for ESP32. This line is for ESP8266. Try this: gotSize = getDirSize(file.path());

I already tested it and it worked fine. :grinning: