Skip to content

Instantly share code, notes, and snippets.

@magicshui
Created September 26, 2014 10:03
Show Gist options
  • Save magicshui/7ab1b51cab0212171402 to your computer and use it in GitHub Desktop.
Save magicshui/7ab1b51cab0212171402 to your computer and use it in GitHub Desktop.
Check if there same images in the folder
#coding: utf-8
import os
import hashlib
my_path = os.path.dirname(os.path.abspath(__file__))+'/qrcodes'
def get_all_files_from_directory():
files = os.listdir(my_path)
return files
def caculate_file_md5(file):
path = my_path+'/'+file
m5 = md5_for_file(path)
return file, m5
def md5_for_file(path):
return hashlib.md5(open(path, 'rb').read()).hexdigest()
i = 0
results = {
}
files = get_all_files_from_directory()
for x in files:
i+=1
f,m = caculate_file_md5(x)
if m in results:
print "file exits:",f ,"\nsame as :",results[m]
print "-"*50
else:
results[m]=f
print "total files:",i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment