{"id":16367956,"url":"https://github.com/papb/batch-rename-by-function","last_synced_at":"2025-07-31T21:05:28.267Z","repository":{"id":57189291,"uuid":"111336038","full_name":"papb/batch-rename-by-function","owner":"papb","description":"Batch rename files and folders by providing a JS function","archived":false,"fork":false,"pushed_at":"2019-01-10T16:49:51.000Z","size":33,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-09T15:55:58.541Z","etag":null,"topics":["batch","cli","javascript","rename"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/papb.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-19T22:08:15.000Z","updated_at":"2022-08-12T14:25:17.000Z","dependencies_parsed_at":"2022-09-15T06:21:29.871Z","dependency_job_id":null,"html_url":"https://github.com/papb/batch-rename-by-function","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/papb%2Fbatch-rename-by-function","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/papb%2Fbatch-rename-by-function/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/papb%2Fbatch-rename-by-function/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/papb%2Fbatch-rename-by-function/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/papb","download_url":"https://codeload.github.com/papb/batch-rename-by-function/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233690967,"owners_count":18714878,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["batch","cli","javascript","rename"],"created_at":"2024-10-11T02:51:16.970Z","updated_at":"2025-01-13T04:20:10.417Z","avatar_url":"https://github.com/papb.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"batch-rename-by-function\n========================\n\n[![npm package](https://nodei.co/npm/batch-rename-by-function.png?downloads=true\u0026downloadRank=true\u0026stars=true)](https://nodei.co/npm/batch-rename-by-function/)\n\n[![NPM version][npm-version-badge]][npm-url]\n[![License][license-badge]][license-url]\n[![NPM downloads][npm-downloads-badge]][npm-url]\n[![Dependency Status][dependency-status-badge]](https://david-dm.org/papb/batch-rename-by-function)\n[![Dev Dependency Status][dev-dependency-status-badge]](https://david-dm.org/papb/batch-rename-by-function)\n[![Open Issues][open-issues-badge]](https://github.com/papb/batch-rename-by-function/issues)\n[![Closed Issues][closed-issues-badge]](https://github.com/papb/batch-rename-by-function/issues?q=is%3Aissue+is%3Aclosed)\n[![contributions welcome][contrib-welcome-badge]](https://github.com/papb/batch-rename-by-function/issues)\n\nBatch rename files and folders by providing a JS function.\n\n# How to use\n\n```\nnpm install -g batch-rename-by-function\n```\n\nNavigate to the folder you want, and create a JS file there, `my-renamer.js`, like this:\n\n```javascript\nmodule.exports = filename =\u003e filename.replace(\"Season 1 - \", \"Season 01 - \");\n```\n\nAnd then execute\n\n```\nbatch-rename-by-function my-renamer.js\n```\n\nto see all the changes that would be made (without actually renaming anything, hence `dry-run`), and if that's really what you want, execute\n\n```\nbatch-rename-by-function my-renamer.js --no-dry-run\n```\n\nto 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`).\n\nThe 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).\n\nTo rename recursively, i.e., rename nested files/folders as well, just use the `--recursive` option (or its alias, `--nested`). This way nested files/folders will be navigated too.\n\nThe renaming function also receives a second parameter, `data`, which is an object that can be useful:\n\n```javascript\nmodule.exports = (filename, data) =\u003e {\n    // Skip folders\n    if (data.isDirectory) return filename;\n\n    // Use data.parentFolder to get the relative path to the parent folder\n    \n    // Use data.depth to know how deep you are in the recursive calls\n    // (recall to use the --recursive option to rename recursively)\n\n    // ...\n};\n```\n\nThe commands `batch-rename-by-function --help` and `batch-rename-by-function --version` are also available:\n\n```\nUsage: batch-rename-by-function path/to/my/renamer/file.js\n\n  Applies the function exported by the given JS file on every file present in\n  the current folder, except the given JS file (if present), including folders.\n\n  The renaming function receives two parameters. The first is the name of the\n  object (file/directory), and the second is a data object with three fields:\n  isDirectory (boolean), depth (int) and parentFolder (string).\n\nOptions:\n  --help                     Show help                                 [boolean]\n  --version                  Show version number                       [boolean]\n  --recursive, --nested      Whether to rename nested files\n                                                      [boolean] [default: false]\n  --no-dry-run, --force, -F  Perform the actual renaming (if omitted, a dry-run\n                             will occur instead, i.e., just a simulation of the\n                             renamings).              [boolean] [default: false]\n\nExamples:\n  batch-rename-by-function myRenamer.js\n```\n\n# Why `batch-rename-by-function`?\n\nA comparison with [`renamer`](https://github.com/75lb/renamer), a more known module for batch renaming:\n\n* `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.\n* You don't have to know JavaScript to use `renamer`, but you must know it to use `batch-rename-by-function`.\n\n# Acknowledgements\n\nThanks Rubens Mariuzzo for [this great guide on creating CLI utilities in NodeJS](https://x-team.com/blog/a-guide-to-creating-a-nodejs-command/).\n\n# Contributing\n\nAny 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.\n\n# Changelog\n\nThe changelog is available in [CHANGELOG.md](CHANGELOG.md).\n\n# License\n\nMIT (c) Pedro Augusto de Paula Barbosa\n\n[npm-url]: https://npmjs.org/package/batch-rename-by-function\n[npm-version-badge]: https://badgen.net/npm/v/batch-rename-by-function\n[dependency-status-badge]: https://badgen.net/david/dep/papb/batch-rename-by-function\n[dev-dependency-status-badge]: https://badgen.net/david/dev/papb/batch-rename-by-function\n[npm-downloads-badge]: https://badgen.net/npm/dt/batch-rename-by-function\n[open-issues-badge]: https://badgen.net/github/open-issues/papb/batch-rename-by-function\n[closed-issues-badge]: https://badgen.net/github/closed-issues/papb/batch-rename-by-function\n[contrib-welcome-badge]: https://badgen.net/badge/contributions/welcome/green\n[license-badge]: https://badgen.net/npm/license/batch-rename-by-function\n[license-url]: LICENSE\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpapb%2Fbatch-rename-by-function","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpapb%2Fbatch-rename-by-function","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpapb%2Fbatch-rename-by-function/lists"}