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:
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.