Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

renamer

Package Overview
Dependencies
Maintainers
1
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

renamer

Batch rename files and folders

  • 0.4.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
19K
decreased by-11.22%
Maintainers
1
Weekly downloads
 
Created
Source

NPM version Build Status Dependency Status Analytics

renamer

Batch rename files and folders.

Install

Install node then:

$ npm install -g renamer

Linux/Mac users may need to run the above with sudo

Usage

$ renamer [--regex] [--find <pattern>] [--replace <string>] [--dry-run] [--verbose] <files>
-f, --find        The find string, or regular expression when --regex is set.
                  If not set, the whole filename will be replaced.
-r, --replace     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.
-i, --insensitive Enable case-insensitive finds.
-d, --dry-run     Used for test runs. Set this to do everything but rename the file.
-v, --verbose     Use to print additional information.
-h, --help        Print usage instructions.

For more information on Regular Expressions, see this useful guide.

Don't forget to test your rename first using --dry-run!

Recursing

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"

Examples

###Simple replace

$ renamer --find '[bad]' --replace '[good]' *
BeforeAfter
.
├── A poem [bad].txt
├── A story [bad].txt
.
├── A poem [good].txt
├── A story [good].txt

###Case insenstive finds

$ renamer --insensitive --find 'mpeg4' --replace 'mp4' *
BeforeAfter
.
├── A video.MPEG4
├── Another video.Mpeg4
.
├── A video.mp4
├── Another video.mp4

###Strip out unwanted text

$ renamer --find 'Season 1 - ' *
BeforeAfter
.
├── Season 1 - Some crappy episode.mp4
├── Season 1 - Load of bollocks.mp4
.
├── Some crappy episode.mp4
├── Load of bollocks.mp4

###Simple filename cleanup

$ renamer --regex --find '.*_(\d+)_.*' --replace 'Video $1.mp4' *
BeforeAfter
.
├── [ag]_Annoying_filename_-_3_[38881CD1].mp4
├── [ag]_Annoying_filename_-_34_[38881CD1].mp4
├── [ag]_Annoying_filename_-_53_[38881CD1].mp4
.
├── Video 3.mp4
├── Video 34.mp4
├── Video 53.mp4

###Give your images a new numbering scheme

$ renamer --replace 'Image{{index}}.jpg' *
BeforeAfter
.
├── IMG_5776.JPG
├── IMG_5777.JPG
├── IMG_5778.JPG
.
├── Image1.jpg
├── Image2.jpg
├── Image3.jpg

###do something about all those full stops

$ renamer --regex --find '\.(?!\w+$)' --replace ' ' *
BeforeAfter
.
├── loads.of.full.stops.every.where.jpeg
├── loads.of.full.stops.every.where.mp4
.
├── loads of full stops every where.jpeg
├── loads of full stops every where.mp4

###if not already done, add your name to a load of files

$ renamer --regex --find '(data\d)(\.\w+)' --replace '$1 (checked by Lloyd)$2' *
BeforeAfter
.
├── data1.csv
├── data2 (checked by Lloyd).csv
├── data3.xls
.
├── data1 (checked by Lloyd).csv
├── data2 (checked by Lloyd).csv
├── data3 (checked by Lloyd).xls

###rename files and folders, recursively

$ renamer --find 'pic' --replace 'photo' '**'
BeforeAfter
.
├── pic1.jpg
├── pic2.jpg
└── pics
    ├── pic3.jpg
    └── pic4.jpg
.
├── photo1.jpg
├── photo2.jpg
└── photos
    ├── photo3.jpg
    └── photo4.jpg

###prefix files and folders, recursively

$ renamer --regex --find '^' --replace 'good-' '**'
BeforeAfter
.
├── pic1.jpg
├── pic2.jpg
└── pics
    ├── pic3.jpg
    └── pic4.jpg
.
├── good-pic1.jpg
├── good-pic2.jpg
└── good-pics
    ├── good-pic3.jpg
    └── good-pic4.jpg

NPM

FAQs

Package last updated on 27 Mar 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc