#coding=utf-8 import os import hashlib def GetFileMd5(filename): if not os.path.isfile(filename): print(filename) return mymd5 = hashlib.md5() f = file(filename,‘rb‘) while True: b = f.read(8096) if not b: break mymd5.update(b) f.close() return mymd5.hexdigest().upper() def bianliDir(foldname): for parent,dirnames,filenames in os.walk(foldname): for filename in filenames: md = GetFileMd5(os.path.join(parent, filename)) os.rename(os.path.join(parent, filename), os.path.join(parent, md)) #print(os.path.join(parent, filename)) print(bianliDir(‘D:/Download/FileAnalysis‘))
时间: 2024-10-17 20:44:43