Search code examples
esp8266arduino-esp8266spiffs

ESP8266 - Reading total and used bytes from Filesystem


I'm trying to check the total size and the used bytes of the Flash-FileSystem on an ESP8266.

I'm using Arduino IDE (2.0.1) with "esp8266 by ESP8266 Community" (3.0.2)

I found in different tutorials the commands

#import <FS.h>

SPIFFS.usedBytes();
SPIFFS.totalBytes();

Also in the arduino-esp32-documentation I found this functions, but the compiler says:

In file included from C:\Users\...\esp8266_temp_humid_log_with_http.ino:38:
C:\Users\...\http_serving.h: In function 'void showFilesize()':
C:\Users\...\http_serving.h:42:24: error: 'class fs::FS' has no member named 'totalBytes'
   42 |   int tBytes = SPIFFS.totalBytes();
      |                        ^~~~~~~~~~
C:\Users\...\http_serving.h:45:25: error: 'class fs::FS' has no member named 'usedBytes'
   45 |   int uBytes = SPIFFS.usedBytes();
      |                         ^~~~~~~~~

exit status 1

Compilation error: 'class fs::FS' has no member named 'totalBytes'

I know, SPIFFS is depricated. I also tried LittleFS with the same result. Unfortunally I cant find the library on my folders to take a look into it.

I don't get it, why this function is not available.

May anyone have an idea to solve the problem?

Thanks a lot.


Solution

  • the comment from Juraj helps me to solve the problem:

    FSInfo fs_info;
    SPIFFS.info(fs_info);
    long usedBytes = fs_info.usedBytes;
    long totalBytes = fs_info.totalBytes;
    

    Thanks for the help.