Directory Notifier

The Directory Notifier is able to monitor a folder and report back when a new file is present. It has several key checks in place to make sure the file isn't actively being written too, or locked by another application before executing the file ready callback.

Unlike the Directory Watch that expects the file to be processed out of the folder, notifier is intended to only signal that a file has been changed, added, or removed. It does not contain a failure policy because of this reason.

  • Directory Notifier is great for supporting hot-reload at runtime.

  • Directory Watch is great for file processing where the file is expected to be removed.

Demo Application

This demo will:

  • Watch the C:\Watch folder.

  • It will report on any JSON files (*.json) - This uses and supports full Regex patterns.

  • It will search TopDirectoryOnly (no subDirectories).

  • NotifyInitial is true which tells the system to send notifications on all files currently in the path.

    • If this was false, it would not call the callback with the pre-existing files.

PerigeeApplication.ApplicationNoInit("HotReloadExample", (c) => {

    c.AddDirectoryNotifier("ReloadConfigs", @"C:\Watch", "*.json", SearchOption.TopDirectoryOnly,
        (ct, l, path) => {
            //path is the full file path of the file that was modified or added, or removed.
            
            //Before loading or reading, verify it's existance:
            if (File.Exists(path))
            {
                //Added / Modified and no longer being written to
            }
            else
            {
                //Removed
            }
        },
        true, null, null, NotifyInitial: true, started: true);

});

Last updated