FS.h and LittleFS.h issue

Hi, I’m having some issue using those 2 libraries.

Since I have to store some user settings on my project I wanted to use them instead of dealing with the eeprom. I declared them like so:

#include "FS.h"
#include <LittleFS.h>

Then I just merged the functions from littlefs example sketch to my code (the one that check that littlefs is working properly) just to check if everything is fine…but it’s not. Here’s the code I copied:

//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX  LittleFs   XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
//XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

void listDir(fs::FS &fs, const char * dirname, uint8_t levels)
{
  Serial.printf("Listing directory: %s\n", dirname);

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

  File file = root.openNextFile();
  while(file)
  {
    if(file.isDirectory())
    {
      Serial.print("  DIR : ");
      Serial.print (file.name());
      time_t t= file.getLastWrite();
      struct tm * tmstruct = localtime(&t);
      Serial.printf("  LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n",(tmstruct->tm_year)+1900,( tmstruct->tm_mon)+1, tmstruct->tm_mday,tmstruct->tm_hour , tmstruct->tm_min, tmstruct->tm_sec);
      if(levels)
      {
        listDir(fs, file.name(), levels -1);
      }
    }
    else
    {
      Serial.print("  FILE: ");
      Serial.print(file.name());
      Serial.print("  SIZE: ");
      Serial.print(file.size());
      time_t t= file.getLastWrite();
      struct tm * tmstruct = localtime(&t);
      Serial.printf("  LAST WRITE: %d-%02d-%02d %02d:%02d:%02d\n",(tmstruct->tm_year)+1900,( tmstruct->tm_mon)+1, tmstruct->tm_mday,tmstruct->tm_hour , tmstruct->tm_min, tmstruct->tm_sec);
    }
    file = root.openNextFile();
  }
}

void createDir(fs::FS &fs, const char * path)
{
  Serial.printf("Creating Dir: %s\n", path);
  if(fs.mkdir(path))
  {
    debugln("Dir created");
  }
  else
  {
    debugln("mkdir failed");
  }
}

void removeDir(fs::FS &fs, const char * path)
{
  Serial.printf("Removing Dir: %s\n", path);
  if(fs.rmdir(path))
  {
    debugln("Dir removed");
  }
  else
  {
    debugln("rmdir failed");
  }
}

void readFile(fs::FS &fs, const char * path)
{
  Serial.printf("Reading file: %s\n", path);

  File file = fs.open(path);
  if(!file)
  {
    debugln("Failed to open file for reading");
        return;
  }

  Serial.print("Read from file: ");
  while(file.available())
  {
    Serial.write(file.read());
  }
  file.close();
}

void writeFile(fs::FS &fs, const char * path, const char * message)
{
  Serial.printf("Writing file: %s\n", path);

  File file = fs.open(path, FILE_WRITE);
  if(!file)
  {
    debugln("Failed to open file for writing");
    return;
  }
  if(file.print(message))
  {
    debugln("File written");
  }
  else
  {
    debugln("Write failed");
  }
  file.close();
}

void appendFile(fs::FS &fs, const char * path, const char * message)
{
  Serial.printf("Appending to file: %s\n", path);

  File file = fs.open(path, FILE_APPEND);
  if(!file)
  {
    debugln("Failed to open file for appending");
    return;
  }
  if(file.print(message))
  {
    debugln("Message appended");
  }
  else
  {
    debugln("Append failed");
  }
  file.close();
}

void renameFile(fs::FS &fs, const char * path1, const char * path2)
{
  Serial.printf("Renaming file %s to %s\n", path1, path2);
  if (fs.rename(path1, path2))
  {
    debugln("File renamed");
  }
  else
  {
    debugln("Rename failed");
  }
}

void deleteFile(fs::FS &fs, const char * path)
{
  Serial.printf("Deleting file: %s\n", path);
  if(fs.remove(path))
  {
    debugln("File deleted");
  }
  else
  {
    debugln("Delete failed");
  }
}

void testFileIO(fs::FS &fs, const char * path){
    Serial.printf("Testing file I/O with %s\r\n", path);

    static uint8_t buf[512];
    size_t len = 0;
    File file = fs.open(path, FILE_WRITE);
    if(!file){
        debugln("- failed to open file for writing");
        return;
    }

    size_t i;
    Serial.print("- writing" );
    uint32_t start = millis();
    for(i=0; i<2048; i++){
        if ((i & 0x001F) == 0x001F){
          Serial.print(".");
        }
        file.write(buf, 512);
    }
    debugln("");
    uint32_t end = millis() - start;
    Serial.printf(" - %u bytes written in %u ms\r\n", 2048 * 512, end);
    file.close();

    file = fs.open(path);
    start = millis();
    end = start;
    i = 0;
    if(file && !file.isDirectory()){
        len = file.size();
        size_t flen = len;
        start = millis();
        Serial.print("- reading" );
        while(len){
            size_t toRead = len;
            if(toRead > 512){
                toRead = 512;
            }
            file.read(buf, toRead);
            if ((i++ & 0x001F) == 0x001F){
              Serial.print(".");
            }
            len -= toRead;
        }
        debugln("");
        end = millis() - start;
        Serial.printf("- %u bytes read in %u ms\r\n", flen, end);
        file.close();
    } else {
        Serial.println("- failed to open file for reading");
    }
}

void testLittleFS()
{
    
  if(!LittleFS.begin(FORMAT_LITTLEFS_IF_FAILED))
  {
    debugln("LittleFS Mount Failed");

  }
  debugln( "Testings LittleFS" );
    
  listDir(LittleFS, "/", 3);
	createDir(LittleFS, "/mydir");
	writeFile(LittleFS, "/mydir/hello2.txt", "Hello2");
	listDir(LittleFS, "/", 1);
	deleteFile(LittleFS, "/mydir/hello2.txt");
	removeDir(LittleFS, "/mydir");
	listDir(LittleFS, "/", 1);
  writeFile(LittleFS, "/hello.txt", "Hello ");
  appendFile(LittleFS, "/hello.txt", "World!\r\n");
  readFile(LittleFS, "/hello.txt");
  renameFile(LittleFS, "/hello.txt", "/foo.txt");
  readFile(LittleFS, "/foo.txt");
  deleteFile(LittleFS, "/foo.txt");
  testFileIO(LittleFS, "/test.txt");
  deleteFile(LittleFS, "/test.txt");
	
  debugln( "Test complete" ); 
}

Whenever a new File instance is called it gives me this error: “file” identifier not defined.

I’m working with a lilygo t-display s3.
Those are my platformio.ini settings:

[platformio]
default_envs = esp32s3

[env:esp32s3]
platform = espressif32
board = lilygo-t-display-s3
framework = arduino
build_flags = 
	-DARDUINO_USB_MODE=1
	-DARDUINO_USB_CDC_ON_BOOT=1
lib_deps = 
	olkal/HX711_ADC@^1.2.12
	bodmer/TFT_eSPI @ ^2.5.30
lib_compat_mode = off

I’ve tested several board and platformio.ini combinations but nothing was able to solve this.

What am i doing wrong?

Alright, don’t ask me why but in case someone else has the same problem that’s how I solved.

In my main cpp sketch I had several includes of libraries plus other includes I wrote. Since the littlefs thing was the very last implementation, I’ve added as last in order. By just simply moving #include “FS.h” and #include <LittleFS.h> to the very top the compiler seems to recognize the File invocation…I don’t know why but now seems to work…for now