Created
December 24, 2018 19:20
-
-
Save nikhil3000/6843171e1bc95f5d53ec175bf1ad7d9f to your computer and use it in GitHub Desktop.
Nodejs code to remove some special characters and numbers from the names of files in a folder
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
var fs = require('fs'); | |
fs.readdir('./data',(err,items)=>{ | |
// console.log(items); | |
items.map(file=>{ | |
let newFile = file.replace(/\d+/g,''); | |
newFile = newFile.replace(/-/g,' '); | |
newFile = newFile.replace(/_/g,' '); | |
fs.rename('./data/'+file, './data/'+newFile, (err)=>{ | |
if(err) | |
console.log(err); | |
console.log(`${file} renamed to ${newFile}`) | |
}) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment