Skip to content

Instantly share code, notes, and snippets.

@kaustavha
Last active February 24, 2019 19:27
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 kaustavha/9274901be9946f64b14557dfacb6c428 to your computer and use it in GitHub Desktop.
Save kaustavha/9274901be9946f64b14557dfacb6c428 to your computer and use it in GitHub Desktop.
Delete all duplicate files in mac
// 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