-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdup.js
45 lines (40 loc) · 1.32 KB
/
dup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const fs = require('fs');
const md5File = require('md5-file')
var hashes = new Map();
console.log('find duplicates started!');
listDir(".")
console.log('ready.')
function listDir(path) {
fs.readdir(path, (err, files) => {
if (err) {
console.log(err)
}
else {
files.forEach(function (name) {
var fullName = path + "/" + name
fs.stat(fullName, (err, stat) => {
if (err) {
console.log(err)
}
else {
if (stat.isDirectory()) {
console.log("d: " + fullName)
listDir(fullName)
}
else {
md5File(fullName, (err, hash) => {
if (hashes.has(hash)) {
hashes.get(hash).push(fullName)
}
else {
hashes.set(hash, [fullName])
}
console.log(hash + " " + hashes.get(hash))
})
}
}
})
});
}
})
}