simple_watcher

File System Watcher for Eiffel

Foundation Layer v1.0.0 MIT

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

FlagValueDescription
Watch_file_name0x0001File creation/deletion/rename
Watch_dir_name0x0002Directory creation/deletion/rename
Watch_attributes0x0004Attribute changes
Watch_size0x0008File size changes
Watch_last_write0x0010Last write time changes
Watch_security0x0020Security descriptor changes
Watch_all0x003FAll of the above

Event Types

TypeCodeDescription
Added1File/directory created
Removed2File/directory deleted
Modified3File/directory modified
Renamed4File/directory renamed

API Reference

SIMPLE_WATCHER

FeatureDescription
make (path, recursive, flags)Create watcher for directory
startBegin watching for changes
pollPoll for next event (non-blocking)
waitWait for next event (blocking)
closeStop watching and release resources
is_validIs the watcher properly initialized?
is_watchingIs the watcher actively monitoring?

SIMPLE_WATCH_EVENT

FeatureDescription
event_typeType of change (1-4)
filenameName of affected file/directory
is_addedWas a file/directory created?
is_removedWas a file/directory deleted?
is_modifiedWas a file/directory modified?
is_renamedWas a file/directory renamed?
event_type_stringHuman-readable event type