Hello. In the standard examples of working with the file system, there is an example of listing files with their sizes. Here he is (Filesystem — ESP8266 Arduino Core 3.1.1-26-g734defb8 documentation):
Dir dir = LittleFS.openDir("/");
while (dir.next()) {
Serial.print(dir.fileName());
if(dir.fileSize()) {
File f = dir.openFile("r");
Serial.println(f.size());
}
}
But, if there is a directory and files in it, then this example cannot determine that this is a directory and even shows its size as zero. In theory, it would be possible to insert a check whether it is a directory or not. It seems to be used for this:
isDirectory
bool amIADir = file.isDir();
But I don't understand how. Can someone tell me how to check correctly?
Alternatively, I tried it like this:
Dir dir = LittleFS.openDir("/");
while (dir.next()) {
Serial.print(dir.fileName());
if(dir.fileName() isDirectory){ // in theory, this would check if the name/file is a directory
Serial.println(String(dir.fileName())+" is a directory");
}
else {
File f = dir.openFile("r");
Serial.println(f.size());
}