I would love for a proper version of this function I found which returns *solely* the new lines from a text/log file. The first call gets the file size and the second call will return only the text that has been added since the first call. Im not sure if there is any other information someone would need from me to make this happen but I would be more than happy to answer any questions to the best of my ability.
I have a semi-working function of this that was written in AHK. The reason I say semi-working is because in my script this function is called very often and after a couple hundred calls it causes the local machine to hard-lock.
P.S. - The original author of this function (denick) has since removed the code from his post because of the issue I mentioned above.
;Returns new lines from a text file. First call gets FileSize, 2nd+ call gets new lines. Converted German to English.
FileTail(File) ;;by denick (http://de.autohotkey.com/forum/topic4619.html)
{
Static OPEN_EXISTING := 3
Static GENERIC_READ := 0x80000000
Static FILE_SHARE_READ := 1
Static FILE_SHARE_WRITE := 2
Static FILE_SHARE_DELETE := 4
Static FILE_BEGIN := 0
Static INVALID_HANDLE_VALUE := -1
Static CF := "" ; Aktuelle Datei (Current File)
Static FP := 0 ; Aktuelle Position in der Datei (File Pointer)
FH := 0 ; Dateihandle (File Handle)
FS := 0 ; Dateigröße (File Size)
FC := "" ; Inhalt der gelesenen Zeilen (File Content)
CL := 0 ; Länge des gelesenen Zeilen (Content Length)
If (File != CF) {
CF := File, FP := 0
}
FH := DllCall("CreateFile"
, "Str", File
, "UInt", GENERIC_READ
, "UInt", FILE_SHARE_READ|FILE_SHARE_WRITE|FILE_SHARE_DELETE
, "UInt", 0
, "UInt", OPEN_EXISTING
, "UInt", 0
, "UInt", 0)
If (FH = INVALID_HANDLE_VALUE) {
CF := "", FP := 0
MsgBox, 262160, FileTail, The file *%File%* could not be opened!
} Else {
DllCall("GetFileSizeEx"
, "UInt", FH
, "Int64P", FS)
If (FP = 0 Or FS <= FP) {
FP := FS
} Else {
DllCall("SetFilePointerEx"
, "UInt", FH
, "Int64", FP
, "UInt", 0
, "UInt", FILE_BEGIN)
CL := VarSetCapacity(FC, FS - FP, 0)
DllCall("ReadFile"
, "UInt", FH
, "UInt", &FC
, "UInt", CL
, "UIntP", CL
, "UInt", 0)
VarSetCapacity(FC, -1)
FP := FS
}
DllCall("CloseHandle", "UInt", FH)
}
Return FC
}