rsegal
23rd March 2005 21:27 UTC
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?
Anders
24th March 2005 03:01 UTC
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
Instructor
24th March 2005 08:26 UTC
How you with FileSeek found start position of last line, for example (very interesting)?
Instructor
24th March 2005 12:00 UTC
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
Instructor
24th March 2005 21:06 UTC
I have completed function: "FileReadFromEnd" v1.0
rsegal
28th March 2005 16:49 UTC
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.