Created
February 4, 2014 05:02
-
-
Save wlaurance/8798406 to your computer and use it in GitHub Desktop.
canonical dates in file names
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 _ = 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