# File filters

Two cards on the [Misc](Users-Misc.md) tab of a user stop things by name: **Filename Filters** stops single kinds of action on names that match, and **Block access to any path matching these patterns** shuts whole paths off.

Both exist for the whole server too, in [Restrictions](Prefs-Restrictions.md) of the Preferences. What is set on a user is **added** to what is set there: a name must pass both.

## Filename Filters

A filter is three things: what it filters, how it compares, and a text.

| What it filters | A matching name |
|---|---|
| **Listing** | is left out of folder listings. The file is still there. Folders are never hidden. |
| **Upload** | cannot be uploaded |
| **Download** | cannot be downloaded |
| **Rename** | cannot be given: nothing can be renamed to it |
| **Delete** | cannot be deleted |

| How it compares | Matches when | Upper and lower case |
|---|---|---|
| **starts with** | the name begins with the text | must be the same |
| **contains** | the text is anywhere in the name | must be the same |
| **ends with** | the name ends with the text | does not matter |

A filter looks at the name alone, the last part of the path, not at the folders above it.

With `!` as the first character of the text, a filter says the opposite: only names that match may pass. "Upload ends with `!.pdf`" lets this user upload nothing but PDF files.

The full description, with the kinds **Any file** and **Any folder** and with patterns, is in [File name filters](Prefs-Restrictions-Filename-Filters.md).

### Examples

| Goal | Filters on the user |
|---|---|
| a partner shall not see work files | Listing ends with `.tmp`, Listing starts with `~` |
| an upload-only account for invoices | Upload ends with `!.pdf` |
| nobody of this group deletes signed files | Delete contains `-signed` |
| no programs from outside | Upload ends with `.exe`, Upload ends with `.bat`, Upload ends with `.msi` |

### How the filters are stored

One text, one filter after another, each as a code, the text and a semicolon: `:UE:.exe;` is "Upload ends with .exe".

| Code | Filters | Code | Compares |
|---|---|---|---|
| `L` | Listing | `S` | starts with |
| `R` | Rename | `C` | contains |
| `U` | Upload | `E` | ends with |
| `D` | Download | | |
| `X` | Delete | | |

So `LS` is "Listing starts with" and `XC` is "Delete contains". The text is what an import or a script writes into the user's value `file_filter`.

## Block access to any path matching these patterns

A path that matches one of these patterns cannot be reached by this user at all, whatever their folders allow: not listed, not read, not written.

| Kind | How it matches |
|---|---|
| **Wildcard** | a simple pattern in which `*` stands for any text, matched against the whole path |
| **Regex** | a regular expression that must match the whole path. Try it in [the pattern tester](Prefs-Misc-Regex-Tester.md). |

The path is the one the user sees, starting with `/`, such as `/projects/alpha/contract.pdf`. A pattern for a folder name anywhere needs something in front and behind:

| Pattern | Kind | Blocks |
|---|---|---|
| `*/private/*` | Wildcard | everything inside any folder named `private` |
| `/projects/*/contracts/*` | Wildcard | the contracts folder of every project |
| `.*\.key` | Regex | every path that ends in `.key` |

## Which one to use

| You want | Use |
|---|---|
| a kind of file not to be uploaded | a filename filter on **Upload** |
| files to be there but not shown | a filename filter on **Listing** |
| a part of a folder tree closed to one group of users | a blocked path on their template |
| files checked by what is in them, not by their name | [Content restrictions](Users-Restrictions-Content.md) |
| a folder closed to a user | do not give it to them: see [The VFS editor](Users-Setup-VFS-Editor.md) |

## Things to know

- Both cards are inherited. Filters on `default` hold for every user, beside the ones of the server.
- A user who overrides a card has only their own entries of **that** card, plus the server's. To add one filter for one user and keep the inherited ones, copy those into the user's card.
- A refused upload is written to the log as "Upload attempt was rejected because the block matching names".
