Skip to content

Instantly share code, notes, and snippets.

@nikhil3000
Created December 24, 2018 19:20
Show Gist options
  • Save nikhil3000/6843171e1bc95f5d53ec175bf1ad7d9f to your computer and use it in GitHub Desktop.
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
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