Skip to content

A safe renaming CLI utility using JavaScript regular expressions.

Notifications You must be signed in to change notification settings

lleaff/node-rename-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rename npm

A simple and safe command-line renaming utility using JavaScript regular expressions.

Prevents renaming collisions and overwriting existing files. Checks for collisions between input files before beginning to rename them, so you don't end up with a dirty directory.

No runtime dependencies outside of Node.js >=v8.

Installation

$ npm install -g safe-rename-cli

The executable is aliased to rename and rename.js.

Usage

 rename.js [OPTION]... PATTERN REPLACEMENT FILE...

 -h, --help              Show this help.
 -v, --verbose           Print extended information.
 -d, --dry-run           Don't modify any file.
 -C, --ignore-collisions Force rename on collision conflicts.
 -S, --skip-problematic  Continue renaming non-problematic files instead of stopping on errors.

Examples

The syntax is similar to calling String#rename in JavaScript.

$ ls
  foo.jsx  bar.jsx  bazjsx
$ rename '\.jsx$' '.js' *
$ ls
  foo.js  bar.js  bazjsx

Capture groups and back references:

$ ls
  foobar  fooBAZbar  fooQUXbar
$ rename '([A-Z]+)bar' 'bar-$1' *
$ ls
  foobar  foobar-BAZ  foobar-QUX

Problematic renaming operation:

$ ls
  foo-10.txt  foo-11.txt  foo-9.txt
$ rename 'foo-(.)\.*' '$1-foo.log' *
  ERROR:  Colliding files:
     "foo-10.txt",
     "foo-11.txt"
  => "1-foo.log"
$ ls
  foo-10.txt  foo-11.txt  foo-9.txt
# Nothing changed, foo-9.txt wasn't touched either.

Here, we can either run rename with -S to skip the conflicting files and deal with them manually later, or we can fix the regular expression so it doesn't produce any collision, e.g.:

$ rename 'foo-([0-9]*)\.*' '$1-foo.log' *
$ ls
  10-foo.log  11-foo.log  9-foo.log

Notes

About

A safe renaming CLI utility using JavaScript regular expressions.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •