python3判断文件是否相同

2021-11-12  本文已影响0人  轩辕夜空
def getHash(f):
    line = f.readline()
    hash = hashlib.md5()
    while (line):
        hash.update(line)
        line = f.readline()
    return hash.hexdigest()


def IsHashEqual(f1, f2):
    str1 = getHash(f1)
    str2 = getHash(f2)
    return str1 == str2


def ifNeedDelete(f1, f2):
    f1s = open(f1, "rb")
    f2s = open(f2, "rb")
    if IsHashEqual(f1s, f2s):
        return True
    else:
        return False
        
if __name__ == '__main__':
    print(ifNeedDelete(f1, f2))
上一篇下一篇

猜你喜欢

热点阅读