Last active
February 15, 2020 07:56
-
-
Save senthilmpro/9cdc042c7972b7b9877bd4b9ac780603 to your computer and use it in GitHub Desktop.
rename-bulk-folder-files.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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