notify
stablePolling-based file system watcher that detects file creation, modification, and deletion events by comparing modification times.
use plugin notify::{FileWatcher.new, watch, unwatch, …} Functions (9)
- FileWatcher.new Create a new file watcher instance
- watch Add a file path to the watch list
- unwatch Remove a file path from the watch list
- poll Check for changes since last poll
- watch_recursive Watch all files in a directory tree
- watched_paths List all currently watched paths
- watch_count Count of currently watched paths
- clear_all Remove all watched paths
- is_watching Check if a specific path is watched
Create a new file watcher instance
Creates a new FileWatcher handle. All other functions operate on this handle as their first argument. The watcher uses polling (comparing mtime from filesystem metadata) so no OS-level event subscription is needed.
use plugin notify::{FileWatcher}
let watcher = FileWatcher.new()
Add a file path to the watch list
Adds a single file path to the watch list, recording its current modification time. On the next poll, changes to this file will be reported.
use plugin notify::{FileWatcher}
let watcher = FileWatcher.new()
watcher.watch("config.json")
watcher.watch("data/records.csv")
Remove a file path from the watch list
Removes a path from the watch list. Future poll calls will no longer report events for this path.
use plugin notify::{FileWatcher}
let watcher = FileWatcher.new()
watcher.watch("temp.txt")
watcher.unwatch("temp.txt")
Check for changes since last poll
Compares current modification times against recorded baselines and returns a table of change events. Each event has {path, event_type} where event_type is "created", "modified", or "deleted". Updates the baseline after reporting.
use plugin notify::{FileWatcher}
let watcher = FileWatcher.new()
watcher.watch("config.json")
let events = watcher.poll()
let i = 1
while events[i] != nil {
let ev = events[i]
print("{ev["path"]}: {ev["event_type"]}")
i = i + 1
}
Watch all files in a directory tree
Recursively traverses a directory and adds every file found to the watch list. Useful for monitoring entire project folders or asset directories for any change.
use plugin notify::{FileWatcher}
let watcher = FileWatcher.new()
watcher.watch_recursive("src/")
print("watching {watcher.watch_count()} files")
List all currently watched paths
Returns a table of all currently watched path strings. Useful for debugging or displaying the watch list.
use plugin notify::{FileWatcher}
let watcher = FileWatcher.new()
watcher.watch("a.txt")
watcher.watch("b.txt")
let paths = watcher.watched_paths()
print("{paths[0]}")
Count of currently watched paths
Returns the number of paths currently being watched.
use plugin notify::{FileWatcher}
let watcher = FileWatcher.new()
watcher.watch_recursive("assets/")
print("watching {watcher.watch_count()} files")
Remove all watched paths
Removes all paths from the watch list at once. The watcher instance remains valid and can be repopulated with new paths.
use plugin notify::{FileWatcher}
let watcher = FileWatcher.new()
watcher.watch_recursive("src/")
watcher.clear_all()
watcher.watch("main.zolo")
Check if a specific path is watched
Returns true if the given path is currently in the watch list, false otherwise.
use plugin notify::{FileWatcher}
let watcher = FileWatcher.new()
watcher.watch("config.json")
print(watcher.is_watching("config.json"))
print(watcher.is_watching("other.json"))