-
Notifications
You must be signed in to change notification settings - Fork 30
Examples
Some real-world examples.
Please note:
- All examples include the dry-run
-d
option to avoid any accidents caused by copy-pasting the commands. - The examples are tailored for Windows users, therefore use double-quotes. Mac/Linux users must use single quotes for the examples to function correctly.
- The basics
- Regular expression examples
- {{index}} token examples
Some examples using plain text --find
and --replace
strings.
The *
wildcard in this command means "all files and directories in the current working directory".
$ renamer -d --find "[bad]" --replace "[good]" *
Before | After |
---|---|
|
|
The **
wildcard in this command matches all files and directories recursively from the current working directory downward.
$ renamer -d --find "pic" --replace "photo" "**"
Before | After |
---|---|
|
|
If the **
pattern is followed by a /
, only directories and subdirectories match.
$ renamer -d --find pic --replace photo "**/"
Before | After |
---|---|
|
|
If omitted, --replace
defaults to an empty string.
$ renamer -d --find "Season 1 - " *
Before | After |
---|---|
|
|
This diagram below highlights the different elements of a path. You can operate on a specific element using the --path-element
option - valid values are base
, name
and ext
.
┌─────────────────────┬────────────┐
│ dir │ base │
├──────┬ ├──────┬─────┤
│ root │ │ name │ ext │
" / home/user/dir / file .txt "
└──────┴──────────────┴──────┴─────┘
This example renames only the file extension.
$ renamer -d --path-element ext --find txt --replace log *
Before | After |
---|---|
|
|
The --find
option accepts a plain string or Javascript regular expression literal. These examples demonstrate using regular expressions in find expressions.
$ renamer -d --find "/^/" --replace "good-" "**"
Before | After |
---|---|
|
|
$ renamer -d --find "/$/" --replace=-good --path-element name "**"
Before | After |
---|---|
|
|
$ renamer -d --find "/mpeg4/i" --replace "mp4" *
Before | After |
---|---|
|
|
By default, matches are replaced only once. Use a regular expression with the g
flag to replace all matches.
$ renamer -d --find "/e/g" --replace "E" *
Before | After |
---|---|
|
|
$ renamer -d --find "/.*_(\d+)_.*/" --replace "Video $1.mp4" *
Before | After |
---|---|
|
|
This example replaces all full-stops except the final one before the extension name.
$ renamer -d --find "/\.(?!\w+$)/g" --replace " " *
Before | After |
---|---|
|
|
$ renamer -d --find "/(data\d)(\.\w+)/" --replace "$1 (checked by Lloyd)$2" *
Before | After |
---|---|
|
|
The special {{index}}
token in the --replace
string will be replaced with a number, incremented every time a file is renamed. This example also highlights that if omitted, the --find
value defaults to the full filename.
$ renamer -d --replace "Image{{index}}.jpg" *
Before | After |
---|---|
|
|
You can specify the format of the {{index}}}
value by passing a printf format string to --index-format
.
$ renamer -d --replace "Image{{index}}.jpg" --index-format %03d *
Before | After |
---|---|
|
|