python - 如何使用 Python 计算文件系统目录的哈希值?

标签 python hash

我正在使用这段代码来计算文件的哈希值:

m = hashlib.md5()
with open("calculator.pdf", 'rb') as fh:
    while True:
        data = fh.read(8192)
        if not data:
            break
        m.update(data)
    hash_value = m.hexdigest()

    print  hash_value

当我在文件夹“folder”上尝试时,我得到了

IOError: [Errno 13] Permission denied: folder

如何计算文件夹的哈希值?

最佳答案

使用 checksumdir python 包可用于计算目录的校验和/哈希。可在 https://pypi.python.org/pypi/checksumdir/1.0.5 获得

用法:

import checksumdir
hash = checksumdir.dirhash("c:\\temp")
print hash

关于python - 如何使用 Python 计算文件系统目录的哈希值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24937495/

相关文章:

python - python 中是否有与 MATLAB 函数 bsxfun 等效的函数?

python - Pyephem 和 pypredict/gpredict 差异

java - 在 Java 中为 XML 生成 SHA-256 哈希

java - 如何散列 2D 平面中的几何点?

python - ValueError : Location based indexing can only have [integer, 整数切片,类似于整数, bool 数组]类型

python - 一次迭代列表中的每 2 个元素

python - 将多个 python 脚本的结果合并到一个语句中

c - 适用于异构元组的快速 8 位校验和算法

node.js - Express.js 如何在登录时和之后使用安全性

perl - 哈希 perl 的切片哈希