Skip to content

Instantly share code, notes, and snippets.

@senthilmpro
Last active February 15, 2020 07:56
Show Gist options
  • Save senthilmpro/9cdc042c7972b7b9877bd4b9ac780603 to your computer and use it in GitHub Desktop.
Save senthilmpro/9cdc042c7972b7b9877bd4b9ac780603 to your computer and use it in GitHub Desktop.
rename-bulk-folder-files.js
const renameFile = (folderPath, strToRemove) => {
const fs = require('fs');
const path = require('path');
const files = fs.readdirSync(folderPath,'utf-8');
files.forEach(v => {
if(v.indexOf(strToRemove) !== -1){
let newName = v.replace(strToRemove, "");
let oldFilePath = path.resolve(folderPath, v);
let newFilePath = path.resolve(folderPath, newName);
fs.renameSync(oldFilePath,newFilePath);
}
});
console.log("Completed");
}
const main = () => {
let path = "/Users/USER_PROFILE/Downloads/";
let strToRemove = "www.mywebsite.com - ";
renameFile(path, strToRemove);
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment