import os
import hashlib
import time
# 这是一个示例 Python 脚本。
# 按 Shift+F10 执行或将其替换为您的代码。
# 按 双击 Shift 在所有地方搜索类、文件、工具窗口、操作和设置。
def showmd5(dirpath):
filenames = os.listdir(dirpath)
for filename in filenames[:]:
filepath = dirpath + '/' + filename
if filepath.endswith('.png') or filepath.endswith('.jpg') or filepath.endswith('jpeg'):
fd = open(filepath, "rb")
f = fd.read()
pmd5 = hashlib.md5(f)
print(filename, pmd5.hexdigest())
def rmd5():
dirpath = input("请输入图片路径:")
writefile = int(time.time() * 1000)
filenames = os.walk(dirpath)
for root, dirs, files in filenames:
for file in files:
file = os.path.join(root, file)
if file.endswith('.png') or file.endswith('.jpg') or file.endswith('jpeg'):
with open(file, "rb") as fd:
f = fd.read()
pmd5 = hashlib.md5(f)
ff = file+" "+pmd5.hexdigest()
with open(file, "a") as f:
f.write(str(writefile))
with open(file, "rb") as fd:
f = fd.read()
pmd5 = hashlib.md5(f)
print(ff+" 改后:"+pmd5.hexdigest())
rmd5()
# 按间距中的绿色按钮以运行脚本。
if __name__ == '__main__':
rmd5()
pthon批量更改图片md5
最新推荐文章于 2025-02-03 22:15:45 发布