Skip to content

Instantly share code, notes, and snippets.

@wlaurance
Created February 4, 2014 05:02
Show Gist options
  • Select an option

  • Save wlaurance/8798406 to your computer and use it in GitHub Desktop.

Select an option

Save wlaurance/8798406 to your computer and use it in GitHub Desktop.
canonical dates in file names
var fs = require('fs');
var _ = require('underscore');
process.stdin.on('data', function(d) {
var files = d.toString().split('\n').filter(function(e){ return e !== ''; });
files.map(function(fn) {
var splat = fn.split('-');
if (splat[0].length <= 2) {
var copy = _.clone(splat);
var year = splat[2];
var month = splat[0];
var day = splat[1];
if (month.length < 2) {
month = "0" + String(month);
}
if (day.length < 2) {
day = "0" + String(day);
}
splat[0] = year;
splat[1] = month;
splat[2] = day;
var newFName = splat.join('-');
fs.linkSync(fn, newFName);
fs.unlinkSync(fn);
} else {
console.log('already ordered correctly');
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment