#coding =utf-8import osimport hashlibdef ergodic (startpath): cu_path= OS.GETCWD () os.chdir (Startpath) file_list=os.listdir (Startpath) for i in file_list: Fullname=os.path.abspath (i) if os.path.isdir (fullname): try: ergodic (FullName) except WindowsError: print fullname+ " doesn ' t exist." elif os.path.isfile (FullName): #f =open (' e:\\result.txt ', ' a ') #f. Write (fullname+ ' \ r \ n ') # F.close () ex_name=fullname[-3:].lower () if ex_name in f_type_ List: md5sum ( FullName) os.chdir (cu_path) def md5sum (filename): fd = open (filename, "RB") fcont = fd.read () fd.close () fmd5 = hashlib.md5 (Fcont). Hexdigest () r=open (' E:\\result.txt ', ' a ') r.write (filename+ ' \ t ' +fmd5+ ' \ r \ n ') r.close () if __name__== "__main__": try: os.remove (' E:\\result.txt ') except windowserror: print "E:\\result.txt doesn ' t exist." search_path= "d:\\" f_type_list= (' rar ', ' zip ') ergodic (Search_path)
Python implements the compression packet lookup, the comparison