# Rename task

A Rename gives each file or folder on the list a new name, where it is. With a path in the new name it also moves the item to another folder of the same place.

## Fields

| Field | What it does | On a new task |
|---|---|---|
| **New Name** | the new name, usually built from [variables](Jobs-Variables.md): `{stem}_{yyyy}{MM}{dd}{ext}`. A name alone keeps the item in its folder. A whole address puts it there. | |
| **Keep trying for x seconds** | a rename that fails is tried again once a second | 0 |
| **Overwrite.** | a file of the new name that is already there is replaced. Without it the rename fails: "Item already exists, so rename failed..." | off |
| **Skip sub items if parent is renamed.** | when a folder on the list is renamed, the files in it that are on the list too are not renamed one by one; their addresses are brought up to date | on |
| **Set modified date to now.** | the renamed item gets the current date | off |
| **Update keywords.** | keywords that users gave the file in the web interface go with it to its new name | off |
| **Route connection through DMZ when possible** | the connection is made from a DMZ server | |

Besides the usual variables, `{item_num}` is the item's place on the list, from 1: `scan_{item_num}.pdf` numbers the files.

## What it hands on

The items under their **new** names: `{url}`, `{name}` and `{path}` are the new ones. The old ones stay available as `{url_old}` and `{name_old}`, for a mail that says what was renamed to what.

When a rename fails after all tries, the task fails: "Rename failed after …".

## Examples

| To | New Name |
|---|---|
| put the date in front | `{yyyy}-{MM}-{dd}_{name}` |
| change the ending | `{stem}.done` |
| small letters only | `{lower_start}{name}{lower_end}` |
| take spaces out | `{replace_start: :_}{name}{replace_end}` |
| take a prefix off | `{substring_start:4:-1}{name}{substring_end}` |
| the date of the file itself | `{-yyyy}{-MM}{-dd}_{name}` |

See [Functions](Jobs-Functions.md).

## Things to know

- **Rename, or Move?** A Rename stays on one server. To take a file to another server under a new name, the new name is the end of a [Copy](Task-Copy.md)'s or Move's destination.
- **Rename to mark.** Renaming a fetched file to `{name}.done` on a partner's server is a common way to not fetch it twice, where you may write there. The Copy task can do that itself: **Rename source after copy**.
- **Names that collide.** Two files that get the same new name overwrite each other with **Overwrite**, and fail without it. Keep something of each file's own in the name: `{stem}`, `{item_num}`.
