Skip to content

Instantly share code, notes, and snippets.

@chrisenytc
Created May 7, 2014 17:42
Show Gist options
  • Save chrisenytc/f9876ffdabb27c5a2b83 to your computer and use it in GitHub Desktop.
Save chrisenytc/f9876ffdabb27c5a2b83 to your computer and use it in GitHub Desktop.
Rename files
'use strict';
/*
* Module Dependencies
*/
var fs = require('fs'),
join = require('path').join,
DIR_PATH = 'images',
NAME_MODEL = 'img';
function renamer(path, name) {
fs.readdir(path, function(err, files) {
if (err) {
throw err;
}
for (var i = 0; i < files.length; i++) {
var newName = name + i;
fs.renameSync(join(path, files[i]), join(path, newName.toUpperCase()));
console.log('Rename > ' + files[i] + ' to > ' + newName.toUpperCase());
};
});
};
renamer(DIR_PATH, NAME_MODEL);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment