sysutils.watch(folder, func)

Monitors a directory for changes in the background.

Parameters

folder

The folder to be watched, as a string or as a Directory

func

A callback function that will be called each time a directory change has been detected.

This function receives the following arguments :
  • The action that occured as a string among "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

local sysutils = require "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()