Archive: Problems with FileRead at end of the file


Problems with FileRead at end of the file
Once again...
I read a textfile with $\r$\n at the end of every line in a loop.
When i get to the end, the last string isn't read. The string is empty "" because i got to the end of the file.
So my idea was to get the position of the last read and then read from there to the end of the file to avoid the "" string, but it doesn't work. Heres the code maybe you have an idea...
$9 is the filehandle


FileSeek $9 0 "END" $R8
FileSeek $9 0
unDOloop:
FileSeek $9 0 "CUR" $R9 ;get file position
FileRead $9 $2 ;Read string from file
StrCmp $2 "" end ;If end of file is reached, exit procedure
StrCpy $R0 $2 3 ;Get first letters and do function accordingly
StrCmp $R0 $R1 "" unDOloop ;if not type of change stated in $R1, seek further
call un.restore_changes ;if this is the right thing, restore values (string already in $2)
goto unDOloop ;and loop till end of the file
end:
;MessageBox MB_OK|MB_TOPMOST|MB_ICONINFORMATION "Last Fileposition : $R9$\r$\nLenght of file : $R8$\r$\nString is $2" 0 0
FileSeek $9 $R9 ;we've read past the end of the file, so get back to start of string
IntOp $R8 $R8 - $R9 ;get length till EOF-1
Intop $R8 $R8 - 1
FileRead $9 $2 $R8 ;read last string in file
StrCmp $2 "" exit ;If still end of file, exit procedure
StrCpy $R0 $2 3 ;Get first letters and do function accordingly
StrCmp $R0 $R1 "" exit ;if not type of change stated in $R1, exit
call un.restore_changes ;restore values (string already in $2)
exit:


KIM


The string is empty "" because i got to the end of the file.
What's wrong with that? What are you tring to do?

What does NSIS do when I try to read a string from the file and get to the end of the file?
The documentation says it returns an empty string, not the string till EOF...
Or am I wrong...


It actually says:

If the end of file is read and no more data is available, the output string will be empty, and the error flag will be set.
This means you won't get the error flag and an empty string if there is still some data left in the buffer. You can safely read until you get an empty string and the error flag knowing that you will get all the data in the file.

Ok, i understood it in a different way...
Thanks.