It would be useful to have a new command to check whether the last file I/O operation on a give file ended in success or failure. Something like GetLastFileError(file) (simila to the C Standard Library ferror() function.
This new command is needed especially when reading data types from file (e.g. ReadByte(), ReadDouble(), etc.), since errors are reported by returning 0, which could also be the read value, so there's no way to know if it was an error except by checking if the file position has moved forward or not — see @Sciro's workaround in the following post:
viewtopic.php?p=534874#p534874
Code: Select all
If CreateFile(0, GetTemporaryDirectory() + "test")
For i = 1 To 10
WriteByte(0, i)
Next
FileSeek(0, 0)
Repeat
oldPos = Loc(0) ; <-- @Sicro's workaround to check if file read operation was successfull
value = ReadByte(0)
newPos = Loc(0)
If oldPos <> newPos
Debug value
Else
Debug "ReadByte: Error"
Break
EndIf
ForEver
CloseFile(0)
Else
Debug "File could not be created!"
EndIf