Skip to content

Instantly share code, notes, and snippets.

@aleroddepaz
Created September 14, 2015 19:16
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 aleroddepaz/bc93938b921a1cc44476 to your computer and use it in GitHub Desktop.
Save aleroddepaz/bc93938b921a1cc44476 to your computer and use it in GitHub Desktop.
import os
import shutil
import filecmp
from itertools import combinations
DIR = 'C:/Alotofwildphotos'
DEST_DIR = 'C:/Alotofwildphotos/Repeated'
files = filter(os.path.isfile, map(lambda f: os.path.join(DIR, f), os.listdir(DIR)))
repeated = { pair[1] for pair in combinations(files, 2) if if filecmp.cmp(*pair) }
print('%s repeated file(s)' % len(repeated))
if not os.path.exists(DEST_DIR):
os.makedirs(DEST_DIR)
for file in repeated:
name = os.path.basename(file)
dest = os.path.join(DEST_DIR, name)
shutil.move(file, dest)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment