# 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](/core-modules/event-sources/watchers/directory-watch.md) 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.&#x20;

{% hint style="success" %}

* Directory Notifier is great for supporting hot-reload at runtime.
* [Directory Watch](/core-modules/event-sources/watchers/directory-watch.md) is great for file processing where the file is expected to be removed.
  {% endhint %}

### 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.

```csharp
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);

});
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.perigee.software/core-modules/event-sources/watchers/directory-notifier.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
