Archive: Reading a file in reverse


Reading a file in reverse
So I've got a text file I want to read in reverse line by line which I believe I should be able to do using FileSeek however because I'm reading the file in reverse order how will I know when I've reached the beginning of the file? The end of the file has the EOF marker does the start have something similar?


maybe not the best way to do it, but u could get the size of the file first, then store that in a var and decrease it when u call FileSeek


How you with FileSeek found start position of last line, for example (very interesting)?


Name "FileReadFromEnd"
OutFile "FileReadFromEnd.exe"

Function FileReadFromEnd
Exch $0
Push $1
Push $2
ClearErrors

StrCpy $2 0
FileOpen $0 $0 r
IfErrors end
FileRead $0 $1
IfErrors +4
Push $1
IntOp $2 $2 + 1
goto -4
FileClose $0

nextline:
StrCmp $2 0 end
IntOp $2 $2 - 1
Pop $0
IntOp $1 $2 + 1
MessageBox MB_YESNO "$1-[$0]$\n$\nNext line?" IDYES nextline

StrCmp $2 0 end
IntOp $2 $2 - 1
Pop $0
StrCmp $2 0 0 -2

end:
Pop $2
Pop $1
Pop $0
FunctionEnd

Section
Push "C:\File.txt"
Call FileReadFromEnd
SectionEnd

I have completed function: "FileReadFromEnd" v1.0


Thanks for the feedback guys. I've been able to come up with a solution involving a few of the functions from the NSIS archive.