Created
June 10, 2014 07:53
-
-
Save hakatashi/69bf6df7129878b2f64a to your computer and use it in GitHub Desktop.
callback地獄
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
require('sugar'); | |
var fs = require('fs'); | |
var filenames = fs.readdirSync('.'); | |
filenames.forEach(function(filename) { | |
if (filename.endsWith('.png') || filename.endsWith('.jpg')) { | |
fs.stat(filename, function(err, stat) { | |
var time = new Date(Math.min(stat.mtime, stat.ctime, stat.atime)); | |
var timeString = time.getFullYear() + '-' + (time.getMonth() + 1).toString().padLeft(2, '0'); | |
fs.exists(timeString, function (exists) { | |
if (!exists) { | |
fs.mkdirSync(timeString); | |
} | |
fs.rename(filename, timeString + '/' + filename, function(err) { | |
if (err) throw err; | |
}); | |
}); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment