DaSpamer Grandmaster Cheater Supreme Reputation: 52
Joined: 13 Sep 2011 Posts: 1578
|
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
Code: | --[[
watchDirectory.add( path:string, callback:function, subtree:boolean, filterFlags:number ):handle
watchDirectory.remove(handle)
notes:
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
end
myPathWatchHandle = watchDirectory.add(myPath,onMyPathChange,false,"folder")
-- remove watch notification from directory
-- watchDirectory.remove(myPathWatchHandle);
--]] |
Description: |
03/01/2021 -- fixed some typo and multiple directories bug |
|
Download |
Filename: |
watch_directory.lua |
Filesize: |
6.31 KB |
Downloaded: |
528 Time(s) |
_________________
|
|