Skip to content

notify

stable

Polling-based file system watcher that detects file creation, modification, and deletion events by comparing modification times.

use plugin notify::{FileWatcher.new, watch, unwatch, …}
9 functions Systems
/ filter jk navigate Esc clear
Functions (9)
  1. FileWatcher.new Create a new file watcher instance
  2. watch Add a file path to the watch list
  3. unwatch Remove a file path from the watch list
  4. poll Check for changes since last poll
  5. watch_recursive Watch all files in a directory tree
  6. watched_paths List all currently watched paths
  7. watch_count Count of currently watched paths
  8. clear_all Remove all watched paths
  9. 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"))
enespt-br