I've writen a simple tail command using vbscript. It works fine except for very large files where it has to read through the entire file to get the last 10 lines. Is there a way to seek to the end of the file and then read backwards for ten lines?Answer1:
I am afraid that seeking backwards is impossible in VBS TextStream, but instead of reading through the entire file you can seek to a position eg. 1K before EOF and then read the rest of the file, displaying only the last 10 lines.
EDIT: I'm adding some sample code to illustrate the idea:
set fso = CreateObject("Scripting.FileSystemObject") set file = fso.GetFile(filePath) set stream = file.OpenAsTextStream(1, -2) pos1KBeforeEnd = file.Size-1024 if pos1KBeforeEnd<0 then pos1KBeforeEnd=0 stream.Skip pos1KBeforeEnd