Skip to content

Instantly share code, notes, and snippets.

@ryanstevens
Created October 5, 2016 06:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanstevens/ad5caaee1826635ec00fd82620ab2375 to your computer and use it in GitHub Desktop.
Save ryanstevens/ad5caaee1826635ec00fd82620ab2375 to your computer and use it in GitHub Desktop.
var md5 = require('md5');
var fs = require('fs');
var crypto = require('crypto');
var async = require('async');
var md5File = require('md5-file');
var path = require('path');
var argv = require('yargs')
.alias('d', 'd')
.default('d', './')
.argv;
var photos = {};
var files = walkSync(argv.d);
files = files.filter(file => {
return (file.toLowerCase().indexOf('.jpg') > 0);
})
async.eachLimit(files, 10, function(file, cb) {
md5File(file, (err, hash) => {
// console.log(hash +'\t\t'+ file);
if (!photos[hash]) photos[hash] = [];
photos[hash].push(file);
setTimeout(cb, 0);
});
}, function() {
Object.keys(photos).forEach((key) => {
if (photos[key].length>1) {
photos[key].forEach((file) => console.log(file));
}
});
});
function walkSync(dir, filelist) {
var fs = fs || require('fs'),
files = fs.readdirSync(dir);
filelist = filelist || [];
files.forEach(function(file) {
if (fs.statSync(dir + '/' + file).isDirectory()) {
filelist = walkSync(dir + '/' + file, filelist);
}
else {
filelist.push(dir + '/' + file);
}
});
return filelist;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment