rename files and folders using regexp
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
LICENSE
README.md
namer.js
package-lock.json
package.json

README.md

node-namer

This is a renaming tool works with regexp.

Install

npm i file-namer -g

Usage

Usage: namer [options]

  Options:

    -f, --find <regexp>          Regexp for finding target string (default: /.*/)
    -r, --replace <replacement>  Replacement string (default: "")
    -m, --match <regexp>         Regexp for matching files (default: the same as find)
    --keep-order                 Do not reorder the file list. By default the namer will reorder file names by their length.
    -y, --yes                    Do not ask for confirmation
    -h, --help                   output usage information

Regexps in the parameters can be with or without // warper(The wraper can be used when you need regexp flags "i" or "g").

You may need to add "\" before some signs in your command environment.

The replacement will become the second parameter of string.replace function in javascript. So several special signs can be used.

Patterns

Special javascript replacement patterns
    $$            Inserts a "$"
    $&            Inserts the matched substring
    $`            Inserts the portion of the string that precedes the matched substring
    $'            Inserts the portion of the string that follows the matched substring
    $n            Inserts the nth submatch group, from 1 ot 100
Extra replacement patterns
    #COUNTER      Inserts a counter number which is the index of the file in the match list (starts from 1)

Examples:

    namer -m w.s -f poi                        #remove string not matches /w.s/ in which file name matches /poi/
    namer -f "p(o+)i" -r "$1"                  #(special replacement patterns)cut "p" and "i" sticks to the "o"s for files that can be matched
    namer -f /aaaaaa/i -r b                    #(ignore case)replace /aaaaaa/i mode to "b" for files that can be matched
    namer -f some.*pics\\.png -r "#COUNTER.png"#change the names to numbers for some png files that can be matched