This example has none of these, hence, #Persistent.#Persistent wrote:This is usually unnecessary because the script is automatically persistent if the program detects that it has some way of launching new threads, such as a hotkey, timer or GUI.
WatchFolder() - updated on 2021-10-14
Re: WatchFolder() - updated on 2016-11-30
Usually #Persistent is not required because there's some other AHK functionality that is used in the script which automatically makes it persistent. However, in that most basic example, it is required.
Re: WatchFolder() - updated on 2016-11-30
@kczx3
Thanks kcx3! At last everything fell into place and the script works great as expected. I had realized #Persistent was missing (before I checked your mention) so I added that and tested but still no good. I then added False (after I checked your reply) and that did the trick! Thanks again, and as a final note, I didn't have to change the Default: 0x03 or any other parameters in the original function.
Thanks kcx3! At last everything fell into place and the script works great as expected. I had realized #Persistent was missing (before I checked your mention) so I added that and tested but still no good. I then added False (after I checked your reply) and that did the trick! Thanks again, and as a final note, I didn't have to change the Default: 0x03 or any other parameters in the original function.
Re: WatchFolder() - updated on 2016-11-30
Hi there, I've just started using this fantastic script to monitor 5 directories for new files downloaded/created and then kick off an exe which scans them for viruses. I run the script as an admin, but at some point after running it hangs forever... Do you have any suggestion for figuring out why? My script is quite minor so I feel like it can't be my code as it works fine for a bit (hence I must have registered my function correctly with Watchfolder()..)
My other thought is maybe it has something to do with setting subtree option to True?
My other thought is maybe it has something to do with setting subtree option to True?
Re: WatchFolder() - updated on 2016-11-30
@Skrell - Even if your script doesn’t have a lot of lines, it can still be the source of the problem. For example, using RunWait could have your script waiting on your virus scan software to close, causing your script to hang up. You should post your script so the forum can determine if there are any potential problems in it.
Re: WatchFolder() - updated on 2016-11-30
I might have fixed it, and your intuition was right! I think it was my fault!! doh!boiler wrote: ↑14 Feb 2021, 11:52@Skrell - Even if your script doesn’t have a lot of lines, it can still be the source of the problem. For example, using RunWait could have your script waiting on your virus scan software to close, causing your script to hang up. You should post your script so the forum can determine if there are any potential problems in it.
Re: WatchFolder() - updated on 2016-11-30
how to exit watch?
I use a global var to break.
I don't know if it's over yet
and the SubTree := False dont work?
I watch "F:\Documents\Pictures\"
but when i move file to "F:\Documents\Pictures\test"
it still msgbox %name%
I use a global var to break.
I don't know if it's over yet
Code: Select all
WatchFolder("F:\Documents\Pictures\", "ReportFunction",false,1)
ReportFunction(Directory, Changes) {
global end
For Each, Change In Changes {
Action := Change.Action
Name := Change.Name
if (end)
Break
If (Action = 1)
msgbox %name%
}
}
#k::
end := 1
return
I watch "F:\Documents\Pictures\"
but when i move file to "F:\Documents\Pictures\test"
it still msgbox %name%
Re: WatchFolder() - updated on 2016-11-30
Code: Select all
; Parameters:
; Folder - The full qualified path of the folder to be watched.
; Pass the string "**PAUSE" and set UserFunc to either True or False to pause respectively resume watching.
; Pass the string "**END" and an arbitrary value in UserFunc to completely stop watching anytime.
; If not, it will be done internally on exit.
; UserFunc - The name of a user-defined function to call on changes. The function must accept at least two parameters:
; 1: The path of the affected folder. The final backslash is not included even if it is a drive's root
; directory (e.g. C:).
; 2: An array of change notifications containing the following keys:
; Action: One of the integer values specified as FILE_ACTION_... (see below).
; In case of renaming Action is set to FILE_ACTION_RENAMED (4).
; Name: The full path of the changed file or folder.
; OldName: The previous path in case of renaming, otherwise not used.
; IsDir: True if Name is a directory; otherwise False. In case of Action 2 (removed) IsDir is always False.
; Pass the string "**DEL" to remove the directory from the list of watched folders.
Re: WatchFolder() - updated on 2016-11-30
Hello @just me , Thanks you too much for that a useful code ,
How i can extract that table to MS.excel or notepad please ?
How i can extract that table to MS.excel or notepad please ?
Re: WatchFolder() - updated on 2016-11-30
Which 'table' do you mean?
Re: WatchFolder() - updated on 2016-11-30
I mean that result which it appear in ListView
Re: WatchFolder() - updated on 2016-11-30
The ListView is not part of the class. The changes are passed to the UserFunc as an array. You can check the MyUserFunc in the sample script to see how this array can be processed.
Re: WatchFolder() - updated on 2016-11-30
I get it , Thanks for the clarification
Re: WatchFolder() - updated on 2021-10-14
*bug-fix 1.0.03.00*
Re: WatchFolder() - updated on 2021-10-14
https://github.com/AHK-just-me/WatchFolder/commit/55f280a472ab3a793a2aca37def9f561b2b04427?diff=split
omg, thank you for fixing this
but I can't understand how you did it
___
aha, recently I have learned how to use a debugger, https://github.com/zero-plusplus/vscode-autohotkey-debug
is it when you RemoveAt, the array reorders ?
so I've been able to use 1 (order doesn't matter), but not 2 (order matters)
I think I've found a bug
MAX_DIR_PATH << !!A_IsUnicode and MAX_DIR_PATH
to get long path, I propose to use:
___
this code is very cool
omg, thank you for fixing this
but I can't understand how you did it
___
aha, recently I have learned how to use a debugger, https://github.com/zero-plusplus/vscode-autohotkey-debug
is it when you RemoveAt, the array reorders ?
so I've been able to use 1 (order doesn't matter), but not 2 (order matters)
I think I've found a bug
Code: Select all
VarSetCapacity(LongPath, MAX_DIR_PATH << !!A_IsUnicode, 0)
If !DllCall("GetLongPathName", "Str", Folder, "Ptr", &LongPath, "UInt", MAX_DIR_PATH)
shouldn't it be the same ?[in] cchBuffer
The size of the buffer lpszLongPath points to, in TCHARs.
MAX_DIR_PATH << !!A_IsUnicode and MAX_DIR_PATH
to get long path, I propose to use:
Code: Select all
Loop, Files, % Folder, D
{
Folder:=A_LoopFileLongPath
}
Code: Select all
For Event, Folder In EventArray {
DllCall("CloseHandle", "Ptr", Folder.Handle)
DllCall("CloseHandle", "Ptr", Event)
}
Re: WatchFolder() - updated on 2021-10-14
@MrDoge,
Yes!... is it when you RemoveAt, the array reorders ?
I don't think so. VarSetCapacity requires to specify RequestedCapacity as bytes, not as TCHARs.I think I've found a bug ...
Re: WatchFolder() - updated on 2021-10-14
How VATCHFOLDER V2 Works with Beta
Re: WatchFolder() - updated on 2021-10-14
@just me
___
now I am able to rewrite it, excluding the DllCall parts (where do you even find which WinAPI function? (CreateFile, GetOverlappedResult) without a C++ background it is hard to understand https://docs.microsoft.com/en-us/windows/win32/fileio/obtaining-directory-change-notifications)
___
I wanted to separate the SetTimer and etc. so there's no need for If (Folder = TimerID) { ; called by timer
this.I this.don't this.really this.like this.to this.use this.classes, but I think I have to: to only use 1 global variable name : WatchFolder
there isn't any difference in functionality (I hope):
3 files here: https://github.com/FuPeiJiang/WatchFolder/tree/class/class
oof, documentation, I should've questionned more why you changed itTCHARs
___
now I am able to rewrite it, excluding the DllCall parts (where do you even find which WinAPI function? (CreateFile, GetOverlappedResult) without a C++ background it is hard to understand https://docs.microsoft.com/en-us/windows/win32/fileio/obtaining-directory-change-notifications)
___
I wanted to separate the SetTimer and etc. so there's no need for If (Folder = TimerID) { ; called by timer
this.I this.don't this.really this.like this.to this.use this.classes, but I think I have to: to only use 1 global variable name : WatchFolder
there isn't any difference in functionality (I hope):
Code: Select all
WatchFolder.Add(Folder, UserFunc, SubTree := False, Watch := 0x03)
WatchFolder.Remove(Folder)
WatchFolder.RemoveAll()
WatchFolder.Pause()
WatchFolder.UnPause() ;Resume is too easily mistaken as Remove
- performance: do not use .Count() for routine: expensive
cons: manually counting this.EventToFolderinfo_Count, prone to errors? - some UI changes in WatchFolder2_sample.ahk
Re: WatchFolder() - updated on 2021-10-14
@MrDoge:
GHND 0x0042 -> Combines GMEM_MOVEABLE and GMEM_ZEROINIT.
How many global names do you need when using the function?... to only use 1 global variable name : WatchFolder
Why do you think that? The method call just returns the contents of a built-in counter:... performance: do not use .Count() for routine: expensive
Code: Select all
ResultType Object::_Count(ExprTokenType &aResultToken, ExprTokenType *aParam[], int aParamCount)
{
aResultToken.SetValue((__int64)mFieldCount);
return OK;
}
You might be wrong.Code: Select all
; DllCall( "GlobalFree", "Ptr",this.WaitObjectsPtr ) ;turns out, this is already freed by _Remove()? so it crashes when I try to free it?
GHND 0x0042 -> Combines GMEM_MOVEABLE and GMEM_ZEROINIT.
The movable-memory flags GHND and GMEM_MOVABLE add unnecessary overhead and require locking to be used safely. They should be avoided unless documentation specifically states that they should be used.
Source: GlobalAlloc()
Re: WatchFolder() - updated on 2021-10-14
Hi @just me
I really appreciate for your great work
just 1 question
is your code cleaning up memory when exiting ? or should I add an on exit function?
I really appreciate for your great work
just 1 question
is your code cleaning up memory when exiting ? or should I add an on exit function?
Spoiler
Re: WatchFolder() - updated on 2021-10-14
seems that your DummyObject does that , would you explain me how?
Return to “Scripts and Functions (v1)”
Who is online
Users browsing this forum: No registered users and 92 guests