Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save jacobrosenthal/7d34558b2a892c6fbdb467f7a549b8b3 to your computer and use it in GitHub Desktop.

Select an option

Save jacobrosenthal/7d34558b2a892c6fbdb467f7a549b8b3 to your computer and use it in GitHub Desktop.
var fs = require('fs');
var moment = require('moment-timezone');
moment().tz("America/Phoenix").format();
fs.readdir( process.argv[2], function (err, files) {
if (err){
console.log("error", err);
return;
}
function convertDate(file){
var something = moment.tz(file.substring(0, 12), "MMDDYYHHmmss", "America/Phoenix");
var newName = something.format('YYYY-MM-DD_HH-mm-ss.SSS');
return newName;
}
console.log(files);
files.forEach(function(file){
var newName = convertDate(file);
fs.renameSync(process.argv[2] + '/' + file, process.argv[3] + '/' + newName + '.jpg', function (err) {
console.log(err);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment