Page 1 of 1

SPIFFS file.size() wrong on newly created file

Posted: Fri Nov 16, 2018 2:53 pm
by cspwcspw
To get the file size one has to open the file and call f.size(). That works. But if opening the file also creates it, the size is wrong.

File f = SPIFFS.open("/test.txt", "a"); // this creates the file if it does not exist. Opens for appending data.
size_t sz = f.size();

f.size() works if the file already exists when opening it. But if the first line of code has to create the file, the size comes out wrong.


Peter