Skip to content

Instantly share code, notes, and snippets.

@shioken
Created October 5, 2017 02:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shioken/bd9aac2bd1679f63c34f933419978169 to your computer and use it in GitHub Desktop.
Save shioken/bd9aac2bd1679f63c34f933419978169 to your computer and use it in GitHub Desktop.
Rename to sequence number
var fs = require('fs');
fs.readdir('.', function(err, files) {
if (err) throw err;
var fileList = [];
var index = 0;
files.filter(function(file) {
return fs.statSync(file).isFile() && /.*snapshot\.jpg$/.test(file);
}).forEach(function(file) {
var newfilename = 'image_' + ('000' + index).slice(-4) + ".jpg";
fs.renameSync(file, newfilename);
index++;
// fileList.push(file);
console.log(file, newfilename);
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment