Overview
simple_watcher provides SCOOP-compatible file system change monitoring for Eiffel applications. It wraps the Win32 ReadDirectoryChangesW API through a clean C interface, enabling real-time detection of file system changes without threading complications.
The library monitors directories for file additions, deletions, modifications, and renames, with configurable watch flags for filtering specific change types. Supports both single-directory and recursive subdirectory monitoring.
Part of the simple_* ecosystem of focused, single-purpose Eiffel libraries.
Quick Start
Installation
<library name="simple_watcher" location="$SIMPLE_EIFFEL/simple_watcher/simple_watcher.ecf"/>
Watch a Directory
local
watcher: SIMPLE_WATCHER
event: detachable SIMPLE_WATCH_EVENT
do
-- Create watcher for a directory
create watcher.make ("C:\MyFolder", False, {SIMPLE_WATCHER}.Watch_all)
if watcher.is_valid then
watcher.start
from until not watcher.is_watching
loop
-- Poll for changes (non-blocking)
event := watcher.poll
if attached event as e then
print ("Event: " + e.event_type_string + " - " + e.filename + "%N")
end
sleep (100) -- Small delay to avoid busy-waiting
end
watcher.close
end
end
Recursive Monitoring
local
watcher: SIMPLE_WATCHER
do
-- Watch directory and all subdirectories
create watcher.make ("C:\MyFolder", True, {SIMPLE_WATCHER}.Watch_all)
if watcher.is_valid then
watcher.start
-- ... monitoring loop ...
watcher.close
end
end
Features
File Changes
Detect file additions, deletions, modifications
Rename Tracking
Track file and directory rename operations
Recursive Mode
Optional monitoring of subdirectories
Non-Blocking
Poll for events without blocking
Watch Flags
| Flag | Value | Description |
|---|---|---|
Watch_file_name | 0x0001 | File creation/deletion/rename |
Watch_dir_name | 0x0002 | Directory creation/deletion/rename |
Watch_attributes | 0x0004 | Attribute changes |
Watch_size | 0x0008 | File size changes |
Watch_last_write | 0x0010 | Last write time changes |
Watch_security | 0x0020 | Security descriptor changes |
Watch_all | 0x003F | All of the above |
Event Types
| Type | Code | Description |
|---|---|---|
| Added | 1 | File/directory created |
| Removed | 2 | File/directory deleted |
| Modified | 3 | File/directory modified |
| Renamed | 4 | File/directory renamed |
API Reference
SIMPLE_WATCHER
| Feature | Description |
|---|---|
make (path, recursive, flags) | Create watcher for directory |
start | Begin watching for changes |
poll | Poll for next event (non-blocking) |
wait | Wait for next event (blocking) |
close | Stop watching and release resources |
is_valid | Is the watcher properly initialized? |
is_watching | Is the watcher actively monitoring? |
SIMPLE_WATCH_EVENT
| Feature | Description |
|---|---|
event_type | Type of change (1-4) |
filename | Name of affected file/directory |
is_added | Was a file/directory created? |
is_removed | Was a file/directory deleted? |
is_modified | Was a file/directory modified? |
is_renamed | Was a file/directory renamed? |
event_type_string | Human-readable event type |