Skip to content

Instantly share code, notes, and snippets.

@deptno
Created February 28, 2016 13:04
Show Gist options
  • Save deptno/0980dba3549f38dcd450 to your computer and use it in GitHub Desktop.
Save deptno/0980dba3549f38dcd450 to your computer and use it in GitHub Desktop.
change files name
const fs = require('fs');
var dirs = fs.readdirSync(__dirname);
var regexp = /[0-9-]+-(.+)/;
dirs.forEach(function(file) {
var stat = fs.lstatSync(file);
if (stat && !stat.isDirectory()) {
if (regexp.test(file)) {
var newName = file.replace(regexp, "$1");
console.log(`filename change ${file} to ${newName}`);
fs.renameSync(file, newName);
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment