Created
February 24, 2013 16:27
-
-
Save geneticgrabbag/5024430 to your computer and use it in GitHub Desktop.
Rename file to standard naming convention.
Node.JS script to take a list of files and rename each to the format YYYYMMDD_hhmmss.ext.
Used by the criminally pedantic when archiving images and movies.
Requires Node.JS version 0.8 or higher.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var path = require('path'); | |
var util = require('util'); | |
var dateFormat = require('dateformat'); | |
process.argv.forEach(function(val, index, array) { | |
if (index < 2) return; | |
if (! fs.existsSync(val)) { | |
console.error("File \"" + val + "\" does not exist."); | |
return; | |
} | |
s = fs.statSync(val); | |
if (!s.isFile()) { | |
console.error("\"" + val + "\" is not a plain file."); | |
return; | |
} | |
mtime = new Date(s.mtime); | |
var newname = dateFormat(mtime, "yyyymmdd_HHMMss") + path.extname(val); | |
console.log(newname); | |
fs.renameSync(val, newname); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment