sysutils.watch(folder, func)function
Monitors a directory for changes in the background.
Parameters
folder
The folder to be watched, as astring or as a Directory
func
A callback function that will be called each time a directory change has been detected.
- The action that occured as a
stringamong"new","removed","modified", or"renamed" - The concerned File or Directory
- A third argument only if the action is
"renamed", which contains the renamed File or Directory
Return value
Returns a Task instance that will run forever in the background.Example
--! luart-extensions
import sysutils
-- function callback for the sysutils.watch() function
local function onChange(action, entry, newentry)
print("Folder change detected : "..entry.name.."\t("..action..")")
end
-- Watch for changes in the current directory
local task = sysutils.watch(sys.currentdir, onChange)
-- creates a file "test.txt"
local f = sys.File('test.txt')
f:open("write")
-- Writes to the file
f:write("it's a test")
f:close()
-- Removes the file
f:remove()
-- sleep to run the background Task
sleep()