首页 > 代码库 > 批量MD5命名文件

批量MD5命名文件

#coding=utf-8import osimport hashlibdef  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‘))