#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‘))
原文地址:http://www.cnblogs.com/xiaobaichuangtianxia/p/3830232.html