Created
June 2, 2017 17:00
-
-
Save poma/7cb88eeceede3cb59478eca09cb0d858 to your computer and use it in GitHub Desktop.
Hard link all duplicate files generated by fdupes
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
import os | |
dupes = []; | |
src = open('fdupes.txt') | |
for fline in src: | |
line = fline.strip() | |
if line: | |
dupes.append(line) | |
else: | |
while len(dupes) > 0 and not os.path.isfile(dupes[0]): | |
del dupes[0] | |
if len(dupes) > 1: | |
base = dupes[0]; | |
del dupes[0] | |
for file in dupes: | |
if os.path.isfile(file): | |
os.remove(file); | |
os.link(base, file) | |
print 'linked ' + file + ' -> ' + base | |
dupes = [] | |
print 'done' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment