The implementation code is as follows:
#!/usr/bin/python#*-*coding:utf8*-*import osimport sysimport hashlibdef md5sum (data): with open (data, "RB") as f:   MD5 = HASHLIB.MD5 () for i in f.read (4096): if i: md5.update (i) else: break md5 = md5.hexdigest () return md5 "" " Finds the specified key in the specified dictionary, appends the value to value corresponding to the key if it exists, and saves a new element as a list if it does not exist, and the same value is saved as a list "" "Def add (Dic, key, value): dic.setdefaUlt (KEY, [ ]). Append (value) def _files (data): dir = os.walk ( Data) dic1 = {} for x, y, z in dir: for i in z: file_path = os.path.join (x, i) add (Dic1, md5sum (File_path), file_path) for i in dic1: #对字典进行循环如果有相同的文件就打印出其md5和文件名 if len (Dic1[i]) > 1: print (I, dic1[i]) if __ name__ == "__main__": _files (Sys.argv[1])
The results of the operation are as follows:
650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M00/98/5C/wKiom1k6eG2jc7JkAABbv2XTr28598.png-wh_500x0-wm_ 3-wmp_4-s_1632686050.png "title="]2f]}h7p464 ' 5_ot2vymy) m.png "alt=" wkiom1k6eg2jc7jkaabbv2xtr28598.png-wh_50 "/ >
This article is from the "Blue _ Storm" blog, make sure to keep this source http://270142877.blog.51cto.com/12869137/1933928
Use Python to calculate the specified directory MD5, find the same file and print according to MD5