Skip to content

Instantly share code, notes, and snippets.

@utgwkk
Created April 5, 2014 14:51
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 utgwkk/9992967 to your computer and use it in GitHub Desktop.
Save utgwkk/9992967 to your computer and use it in GitHub Desktop.
# coding: utf-8
import os
import hashlib
from glob import glob
flist = []
fmd5 = []
dl = []
dirname = './images/'
for e in ['png', 'jpg']: flist.extend(glob('%s/*.%s'%(dirname,e)))
for fn in flist:
with open(fn, 'rb') as fin:
data = fin.read()
m = hashlib.md5(data)
fmd5.append(m.hexdigest())
for i in xrange(len(flist)):
if flist[i] in dl: continue
for j in xrange(i+1, len(flist)):
if flist[j] in dl: continue
if fmd5[i] == fmd5[j] and not flist[j] in dl:
dl.append(flist[j])
for a in dl: os.remove(a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment