我有一个hashcomparator.pypython脚本,它在脚本中打开一个文件夹,然后应该计算每个文件的哈希值,打开第二个文件夹,计算文件的哈希值,然后比较哈希值
import hashlib
import glob
#Open the input folder
path = "C:\\Users\\luis.henrique\\Documents\\filesin\\"
#scrolls through all .txt files
filesin = [f for f in glob.glob(path + "**/*.txt", recursive=True)]
#calculate hash of .txt files
hash_object = hashlib.sha256(b'filesin')
hex_dig = hash_object.hexdigest()
#Open the output folder
path = "C:\\Users\\luis.henrique\\Documents\\filesout\\"
#scrolls through all .txt files
filesout = [f for f in glob.glob(path + "**/*.txt", recursive=True)]
#calculate hash of .txt files
hash_object = hashlib.sha256(b'filesout')
hex_dig = hash_object.hexdigest()
if filesin == filesout:
print ("The MD5 Hashes of the files are the same.")
print (filesin)
print(hex_dig)
print ("\n")
print (filesout)
print(hex_dig)
else:
print ("The MD5 Hashes are not the same.")
print(hex_dig)
但我无法计算和比较每个文件的哈希值
您正在用glob构建文件列表,但是您不会将这些文件发送到hashlib函数。而是传递字符串“filesin”。您必须为每个文件提供数据,注意不要超过缓冲区大小。这应该让你开始:
相关问题 更多 >
编程相关推荐