Go Down

Topic: Detecting if a file is corrupt (Read 1 time) previous topic - next topic

logger

Hallo

i would like to know if and how exactly you can check if an file is corrupt or not

am opening a file every 5min, write data to it an closing it again(so EOF is written) a every 5 min 24/7
im openng is by
logFile = SD.open(fullName, O_CREAT | O_APPEND| O_WRITE);  So try to find in the file where it has written the last character

but is there a way to detect is an EOF is present ?

a File object referring to the opened file; if the file couldn't be opened, this object will evaluate to false in a boolean context, i.e. you can test the return value with "if (f)".
So if a file is present  and (!SD.open(fullName, O_CREAT | O_APPEND| O_WRITE) == false), cannot be opened
its a detection if file is corrupt is if correct

but nead the  O_APPEND a EOF ??

or is there a better way to detect ?


PaulS

How are you defining corrupted? Typically, all that it means is that the file does not contain as much usable data as you expected.

Quote
So try to find in the file where it has written the last character

That's what the open() method does, when called that way. It finds the EOF in the file, and positions the write cursor at that location.

logger


How are you defining corrupted? Typically, all that it means is that the file does not contain as much usable data as you expected.

Quote
So try to find in the file where it has written the last character

That's what the open() method does, when called that way. It finds the EOF in the file, and positions the write cursor at that location.


i will use this now, when file does exist
logFile = SD.open(fullName, O_APPEND| O_WRITE);  //First open file
if (!logFile)     //  if file cannot be opened and/or the EOF could not be found logFile==false
in this case i will make a new file

Go Up