Pages: [1]   Go Down
Author Topic: Detecting if a file is corrupt  (Read 1359 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 32
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ?

Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 610
Posts: 49071
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 32
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1]   Go Up
Jump to: