当前位置:   article > 正文

python生成文件md5,用Python生成一个包含多个文件的MD5 / SHA1校验和

python对文件md5校验

I have looked through several topics about calculating checksums of files in Python but none of them answered the question about one sum from multiple files. I have several files in sub directories and would like to determine if there was any change in one or more of them.

Is there a way to generate one sum from multiple files?

EDIT:

This is the way I do it to get a list of sums:

checksums = [(fname, hashlib.md5(open(fname, 'rb').read()).digest()) for fname in flist]

解决方案

So I made it :) This way one hash sum is generated for a file list.

hash_obj = hashlib.md5(open(flist[0], 'rb').read())

for fname in flist[1:]:

hash_obj.update(open(fname, 'rb').read())

checksum = hash_obj.digest()

Thank you PM 2Ring for your input!

Note that md5 has been cracked so use it only for non security critical purposes.

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/340148
推荐阅读
相关标签
  

闽ICP备14008679号