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

batch-rename-by-function

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

batch-rename-by-function

Batch rename files and folders by providing a JS function

  • 1.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
increased by50%
Maintainers
1
Weekly downloads
 
Created
Source

batch-rename-by-function

npm package

NPM version License NPM downloads Dependency Status Dev Dependency Status Open Issues Closed Issues contributions welcome

Batch rename files and folders by providing a JS function.

How to use

npm install -g batch-rename-by-function

Navigate to the folder you want, and create a JS file there, my-renamer.js, like this:

module.exports = filename => filename.replace("Season 1 - ", "Season 01 - ");

And then execute

batch-rename-by-function my-renamer.js

to see all the changes that would be made (without actually renaming anything, hence dry-run), and if that's really what you want, execute

batch-rename-by-function my-renamer.js --no-dry-run

to perform the actual renaming. Note that batch-rename-by-function acts on every file/folder in the current working directory, and runs in dry-run mode (i.e. simulation mode) by default. To actually rename files, the --no-dry-run options must be set (or its alias --force or even -F).

The file my-renamer.js doesn't have to be in the same folder as the renames (just give the relative path for it). Also, batch-rename-by-function will automatically skip your JS file (in this example, my-renamer.js) if it is present in the current directory (instead of trying to rename it as well).

The renaming function also receives a second boolean parameter, isDirectory, that can be useful:

module.exports = (filename, isDirectory) => {
    // Skip folders
    if (isDirectory) return filename;

    // ...
};

The commands batch-rename-by-function --help and batch-rename-by-function --version are also available:

Usage: batch-rename-by-function path/to/my/renamer/file.js

  Applies the function exported by the given JS file on every file present in
  the current folder, except the given JS file (if present), including folders.

  The renaming function receives two parameters. The first is the name of the
  object (file/directory), and the second is a boolean which is true iff it is a
  directory. This way directories can be easily skipped, if desired.

Options:
  --help     Show help                                                 [boolean]
  --version  Show version number                                       [boolean]
  --dry-run  Show which renames would happen without actually performing them
                                                      [boolean] [default: false]

Examples:
  batch-rename-by-function myRenamer.js

Why batch-rename-by-function?

A comparison with renamer, a more known module for batch renaming:

  • batch-rename-by-function allows you to write arbitrarily complicated javascript to calculate the new names for your files in a very straightforward way, while to do this with renamer you would have to develop a custom plugin.
  • renamer has support for renaming nested files, while batch-rename-by-function does have it yet (see #2).
  • You don't have to know JavaScript to use renamer, but you must know it to use batch-rename-by-function.

Acknowledgements

Thanks Rubens Mariuzzo for this great guide on creating CLI utilities in NodeJS.

Contributing

Any contribution is very welcome. Feel free to open an issue about anything: questions, suggestions, feature requests, bugs, improvements, mistakes, whatever. I will be always looking.

Changelog

The changelog is available in CHANGELOG.md.

License

MIT (c) Pedro Augusto de Paula Barbosa

Keywords

FAQs

Package last updated on 02 Dec 2018

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