import os
import hashlib
def file_md5(file_name, block_size=2**20):
if not os.path.isfile(file_name):
return
hash = hashlib.md5()
with open(file_name, 'rb') as f:
while True:
b = f.read(block_size)
if not b:
break
hash.update(b)
return hash.hexdigest()
for root, dirs, files in os.walk("your_path"):
for file in files:
file_path = os.path.join(root, file)
md5 = file_md5(file_path)
print file_path, md5
if md5:
os.rename(file_path, os.path.join(root, md5))
Python 修改目录下所有文件名为MD5
最新推荐文章于 2023-07-30 16:18:42 发布