A simple, lightweight Node.js utility for bulk renaming files in a specified directory. This tool provides a flexible way to rename files based on a custom renaming function you define.
- Simple and easy to use
- Rename files in bulk with a custom renaming function
- Pure Node.js, no external dependencies
Since this tool is a simple script, it doesn't need to be installed through npm. You can copy the index.js
file into your project or any desired directory.
-
Ensure you have Node.js installed on your system.
-
Copy the
index.js
file into your project or a specific directory. -
Modify the
myDirectoryPath
variable in theindex.js
file to specify the directory containing the files you want to rename. -
Define your custom renaming logic in the
renameFunction
. This function takes the current filename as an argument and should return the new filename. -
Run the script with Node.js:
node index.js
Suppose you want to prepend "new_" to every file name in the directory "/path/to/your/directory". Your renameFunction
would look like this:
(fileName) => {
return 'new_' + fileName;
}
The renameFunction
is where you define how the files should be renamed. It receives the current filename as an argument and must return the new filename. Here's the prototype:
/**
* @param {string} fileName - The current file name
* @return {string} The new file name
*/
function renameFunction(fileName) {
// Implement your renaming logic here
return fileName; // Modify this line
}
Feel free to fork the repository and submit pull requests with enhancements or fixes.
This project is open source and available under the MIT License.