I've been trying to use this function that I found, the purpose of it is to monitor a file's contents. When I run it monitoring just one file, I test it by modifying the text file manually and it succedes in showing me what I have updated the file with. However when I try it with two files, I don't get any updates in the message boxes. Does anybody know if it is possible to use this function to monitor multiple files? I'm a bit stuck! Thanks!
Code: Select all
#Persistent
file1=C:\Users\Rob\Desktop\f1.txt
file2=C:\Users\Rob\Desktop\f2.txt
SetTimer, FILE_CHECK, 1000
FILE_CHECK:
if (x1 := checkfile(file1)) {
msgbox x1=%x1%
}
if (x2 := checkfile(file2)) {
msgbox x2=%x2%
}
return
CheckFile(File) {
; THX Sean for File.ahk : http://www.autohotkey.com/forum/post-124759.html
Static CF := "" ; Current File
Static FP := ; File Pointer
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
BatchLines := A_BatchLines
SetBatchLines, -1
If (File != CF) {
CF := File
FP := 0
}
hFile := 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 (!hFile) {
CF := ""
FP := 0
SetBatchLines, %BatchLines%
Return False
}
DllCall("GetFileSizeEx"
, "Uint", hFile
, "Int64P", nSize)
If (FP = 0 Or nSize <= FP) {
FP := nSize
SetBatchLines, %BatchLines%
DllCall("CloseHandle", "Uint", hFile) ; close file
Return False
}
DllCall("SetFilePointerEx"
, "Uint", hFile
, "Int64", FP
, "Uint", 0
, "Uint", FILE_BEGIN)
VarSetCapacity(Tail, Length := nSize - FP, 0)
DllCall("ReadFile"
, "Uint", hFile
, "Str", Tail
, "Uint", Length
, "UintP", Length
, "Uint", 0)
DllCall("CloseHandle", "Uint", hFile)
VarSetCapacity(Tail, -1)
FP := nSize
SetBatchLines, %BatchLines%
Return Tail
} file=Script.ahk]