# Folder Monitor

The Folder Monitor section of [Preferences](Prefs.md) holds rules that keep folders on the server machine tidy. Each rule watches one folder and acts on what has become old in it: it deletes the items, moves them to an archive folder, or hands them to a job.

![The Folder Monitor section with two rules](Prefs-Folder-Monitor/section.png)

> [!WARNING]
> A rule deletes or moves files for good, without asking and without a trash. Try a new rule on a copy of the folder first, and read [Folders](#folders) before you tick anything about folders.

With an Enterprise licence the page points you to Jobs instead: a job can do everything a rule here does, and more. The rules work with every licence.

## The list

| Button | What it does |
|---|---|
| **Add** | makes a new rule and opens it. It starts switched off, with a folder, an age of 30 days and an archive folder that are only examples: change them. |
| **Delete** | removes the selected rule, after a question |

A rule that is not enabled is marked **DISABLED** in the list. Nothing counts until **Save** at the bottom ([saving](Prefs.md#saving)); after that the server uses the rules at its next check, without a restart.

## A rule

![A rule](Prefs-Folder-Monitor/rule.png)

| Setting | What it does | In a new rule |
|---|---|---|
| **Enabled** | the rule is used | off |
| **Folder location** | the folder to watch: a path on the server machine itself. Rules do not reach remote storage. | `/myFolder/folderX/` |
| **And path to item matches** | only items whose whole path fits this pattern are touched. `*` stands for any text. | `*` |
| **And doesn't match path** | items whose whole path fits this pattern are left alone | empty |
| **And doesn't match name** | items whose name fits this pattern are left alone, such as `*.keep` | empty |
| **Files** | the rule acts on files | on |
| **Empty folders** | the rule acts on folders that are empty | off |
| **Non empty folders** | the rule acts on folders that hold something | off |
| **Monitor subfolders** | looks into all folders below the watched one. Off: only at what lies directly in it. | on |
| **Count folders when checking if empty**, **Count files when checking if empty** | what makes a folder "not empty" when items are deleted: files in it, folders in it, or both. Names that begin with a dot never count. | files |
| **Expires when** | how old an item must be, as a number of **Minutes**, **Hours** or **Days** | 30 Days |
| **Action to take** | what happens to the items, see below. A rule that is enabled must have one: the page does not save it without, and says "Choose what the rule for … does, or turn the rule off. Without an action it does nothing. Nothing was saved." | nothing |

**Browse** picks a folder on the server machine's own disk, which is where the server looks for it, and writes it with a slash at the end.

A rule without an action that was saved by an earlier version shows "no action" in the list. The server passes over it, and names it in the log once.

### How old is old

The age of an item is the time since it was last changed. A file is old when that is longer ago than **Expires when**. The server checks all rules once a minute, so a rule of 5 minutes acts on a file between 5 and 6 minutes after it was last written.

A negative number means seconds, whatever the unit says, and such a rule is checked every second: `-10` acts on a file 10 seconds after it was last changed. Use it for folders that must be emptied quickly.

### Action to take

| Action | What happens to the items that were found |
|---|---|
| **Archive Or Delete**, with **Delete items found** ticked | they are deleted |
| **Archive Or Delete**, with **Delete items found** not ticked | they are moved into **Archive to folder**. The folder is made if it is not there, and each item keeps its path below the watched folder: `/data/incoming/2026/a.csv` goes to `/data/archive/incoming/2026/a.csv`. If an item of that name is already there, a number is put behind the name. Nothing is compressed. |
| a name under **Plugin** or **Job** | the rule itself neither deletes nor moves. It starts that job with the items it found as the job's files, and the job decides what happens to them. The two settings below the action go away, as they have no part in it. |

The list of actions holds every job of the server and every CrushTask plugin that is set up.

### Folders

Folders need care, because a folder's own date and the dates of what is in it are different things.

- With **Delete items found**: an old folder that the rule may act on is emptied of the items in it that are old themselves, and deleted when nothing is left in it. Items that are newer, or that fit a "doesn't match" pattern, stay, and then so does the folder.
- With an archive folder: an old folder that the rule may act on is moved as a whole, with everything in it, whatever the age of the files inside. A folder's date changes when something is put directly into it or taken out of it, not when a file deeper down changes.

Leave **Non empty folders** off unless you want exactly that.

The watched folder itself is never deleted or moved.

## What a run looks like

Each thing a rule does is written to the log:

```
SERVER|11/20/2026 15:56:13.965|FolderMonitor:Moving file /data/incoming/old.txt to /data/archive/incoming//old.txt
SERVER|11/20/2026 15:56:13.966|FolderMonitor:Moving file /data/incoming/sub/old2.log to /data/archive/incoming//sub/old2.log
SERVER|11/20/2026 15:56:13.967|FolderMonitor:delete folder /data/exports/emptydir
SERVER|11/20/2026 15:56:13.967|FolderMonitor:Deleting file /data/exports/old.tmp
```

Here one rule moved two files that were older than a day and left a new one where it was; another deleted an old file and an old empty folder, and left `old.keep` alone because of **And doesn't match name** `*.keep`.

A rule whose folder does not exist is passed over without a message.
