Last active
February 24, 2019 19:27
-
-
Save kaustavha/9274901be9946f64b14557dfacb6c428 to your computer and use it in GitHub Desktop.
Delete all duplicate files in mac
This file contains 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
// cd to the dir// or open a iterm window - rclick , new console/iterm2 | |
// > node | |
let arr = fs.readdirSync('.'), dupcheck = [], outarr = [], | |
add = a => a[0] + a[1]; | |
arr.forEach(i => { | |
if (i.split(' ').length > 1) { | |
if (dupcheck.indexOf(add(i.split(' '))) !== -1) { | |
outarr.push(i.split(' ')); | |
} | |
dupcheck.push(add(i.split(' '))) | |
} else if (dupcheck.indexOf(add(i.split('.'))) == -1) { | |
dupcheck.push(add(i.split('.'))) | |
} | |
}); | |
arr.forEach(i => { | |
if (i.split(' ').length > 1 && outarr.indexOf(i.split(' '))) { | |
console.log(i); | |
fs.unlinkSync(i); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment