Batch rename files and folders.
Install node then:
$ npm install -g renamer
Linux/Mac users may need to run the above with sudo
renamer
Batch rename files and folders.
Usage
$ renamer <options> <files>
-f, --find <string> The find string, or regular expression when --regex is set. If not set, the whole filename will be replaced.
-r, --replace <string> The replace string. With --regex set, --replace can reference parenthesised substrings from --find with $1, $2, $3
etc. If omitted, defaults to a blank string. The special token '{{index}}' will insert an incrementing number per
file processed.
-e, --regex When set, --find is intepreted as a regular expression.
-d, --dry-run Used for test runs. Set this to do everything but rename the file.
-i, --insensitive Enable case-insensitive finds.
-v, --verbose Use to print additional information.
-h, --help Print usage instructions.
for more detailed instructions, visit https://github.com/75lb/renamer
For more information on Regular Expressions, see this useful guide.
Don't forget to test your rename first using --dry-run
!
Renamer comes with globbing support built in (provided by node-glob), enabling recursive operations. To recurse, use the **
wildcard where a directory name would appear to apply the meaning "any directory, including this one".
For example, this command operates on all js files in the current directory:
$ renamer --find this --replace that '*.js'
this command operates on all js files, recursively:
$ renamer --find this --replace that '**/*.js'
this command operates on all js files from the lib
directory downward:
$ renamer --find this --replace that 'lib/**/*.js'
Bash users without globstar will need to enclose the glob expression in quotes to prevent native file expansion, i.e. '**/*.js'
Some real-world examples.
Windows users: the single-quotation marks used in the example commands below are for bash (Mac/Linux) users, please replace these with double-quotation marks on Windows.
$ renamer --find '[bad]' --replace '[good]' *
Before | After |
---|---|
|
|
$ renamer --insensitive --find 'mpeg4' --replace 'mp4' *
Before | After |
---|---|
|
|
$ renamer --find 'Season 1 - ' *
Before | After |
---|---|
|
|
$ renamer --regex --find '.*_(\d+)_.*' --replace 'Video $1.mp4' *
Before | After |
---|---|
|
|
$ renamer --replace 'Image{{index}}.jpg' *
Before | After |
---|---|
|
|
$ renamer --regex --find '\.(?!\w+$)' --replace ' ' *
Before | After |
---|---|
|
|
$ renamer --regex --find '(data\d)(\.\w+)' --replace '$1 (checked by Lloyd)$2' *
Before | After |
---|---|
|
|
$ renamer --find 'pic' --replace 'photo' '**'
Before | After |
---|---|
|
|
$ renamer --regex --find '^' --replace 'good-' '**'
Before | After |
---|---|
|
|
© 2012-16 Lloyd Brookes <75pound@gmail.com>. Documented by jsdoc-to-markdown.