Grandmaster Cheater Supreme
Joined: 13 Sep 2011
|Posted: Sun Jan 03, 2021 10:47 am Post subject: Watch Directory
|Working on project workspace for Script Editor, for responsiveness and sake of not polling information every few seconds built this small module.
Ported from this
Place in Autorun and access through watchDirectory table, or require.
Some how to use/information
watchDirectory.add( path:string, callback:function, subtree:boolean, filterFlags:number ):handle
path: full path string (max length of MAX_PATH - 260), you cannot watch the same path!
subtree: track changes to child directories as well
filterFlags: pass "folder" to watch changes to files/folders (creation/deletion of directories/files,*renaming is deleting and then creating)
otherwise default is watch only files (create/delete/write events)
for more information refer to: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-findfirstchangenotificationa
*this class cannot pass what files or kind of changes has occured, to the callback function.
-- example script....
local myPath = "C:\\MyPath\\"
local onMyPathChange = function()
print('A change occured to the path:',myPath); -- when a file
myPathWatchHandle = watchDirectory.add(myPath,onMyPathChange,false,"folder")
-- remove watch notification from directory
|03/01/2021 -- fixed some typo and multiple directories bug
|| 6.31 KB
|| 21 Time(s)