Yuari
Documentation
Docs/DirectoryWatcher/DirectoryWatcher.new

DirectoryWatcher.new(path?, recursive?)

Creates and starts a watcher; OnChanged fires for every change kind and Destroy stops it.

Syntax

DirectoryWatcher.new(path: string?, recursive: boolean?) -> DirectoryWatcher

Parameters

ParameterTypeDescription
pathstring?Workspace-relative folder. Defaults to the workspace root.
recursiveboolean?Watch subfolders too.

Returns

TypeDescription
DirectoryWatcherRunning watcher object.

Description

Logic change: new() now auto-starts the watcher (the folder is opened and a monitor thread queues changes immediately). Calling start() again is a no-op while running.

Logic change: events are dispatched from the executor scheduler tick instead of a Lua pump thread. OnChanged now receives created, modified, deleted and renamed events (previously only modified), along with the workspace-relative path.

The metatable is registered as DirectoryWatcher.Metatable so property access works, On* properties return event objects with :Connect, and watchers expose Destroy().

Example

local watcher = DirectoryWatcher.new("scripts")
watcher.OnChanged:Connect(function(path)
    print("changed", path)
end)
writefile("scripts/new.lua", "print(1)")

Notes

  • Destroy stops the monitor thread and closes the directory handle.
  • Direct setters such as DirectoryWatcher.OnChanged(watcher, callback) still work.