import base64
import hashlib
import os
g_origin_path = "【目录】"
g_target_path = "【目录】"
def get_file_md5(filepath):
f = open(filepath, 'rb')
md5obj = hashlib.md5()
md5obj.update(f.read())
hash = md5obj.hexdigest()
f.close()
return str(hash).upper()
for root, dirs, files in os.walk(g_origin_path):
for file in files:
origin_file_path = os.path.join(root, file)
strlist = origin_file_path.split('\\')
target_file_path = g_origin_path + '\\'.join(strlist[5:])
if os.path.exists(target_file_path) == False:
print("多出文件: {} ".format(target_file_path))
continue
origin_file_md5 = get_file_md5(origin_file_path)
target_file_md5 = get_file_md5(target_file_path)
#print(origin_file_md5, target_file_md5)
if origin_file_md5 != target_file_md5:
print("md5不同 路径: {} src: {} target: {}".format(
target_file_path, origin_file_md5, target_file_md5))
网上的东西都不怎么靠谱,用来快速确认有没有后门之类的东西
标签:origin,target,Python,校验,file,path,MD5,os,md5 From: https://www.cnblogs.com/geek233/p/16640172.html