Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: Binary read last line file
Can you tell me another method to reach the end of file without reading the file record by record?
The code would look something like this....
file="C:\Temp\abc.txt" fsize=FileSize(file) buffer=BinaryAlloc(fsize) ;read file into binary buffer BinaryRead(buffer,file) endoffile=BinaryEODGet(buffer)-1 While 1 ;locate lines by getting pointers to @CRLFS beginptr=BinaryIndexEx(buffer,endoffile,@CRLF,@BACKSCAN,0) if beginptr != '-1' endptr=endoffile-beginptr+1 lastline=BinaryPeekStr(buffer,beginptr,endptr) if lastline=="" || lastline==@CRLF endoffile=endoffile-2 continue endif ;trim @CLRF off string lastline=strReplace(lastline,@CRLF,'') message("Last Line",lastline) break else message("CRLF Not Found"," Not a valid ascii file.") break endif endwhile BinaryFree(buffer) message("Last line retriever","Done")
Article ID: W14711
Filename: Quickly read last line in text file.txt
File Created: 2000:06:14:15:09:08
Last Updated: 2000:06:14:15:09:08