Rename files with nodejs

2015-07-19

Simple (super dumb, non-generic) script to rename files in a given relative dir.

Use at your own risk. It's only lazily doing something I quickly need.

Code:
var fs = require('fs');

var dir = process.argv[2];
fs.readdirSync(dir).forEach(function(file){
var newfile = file.replace(/^(\s*\d\d?\s*[\.-]?\s*[\.-]?\s*)/, '');
if (newfile !== file) {
console.log(file);
fs.renameSync(dir+'/'+file, dir+'/'+newfile);
}
});