python-workout icon indicating copy to clipboard operation
python-workout copied to clipboard

e21b1_md5_files.py (calculate the MD5 hash for the contents of every file)

Open Miguel-Ojeda opened this issue 3 years ago • 0 comments

I think you are calculating the MD5 of the filename string... not of the content of the file...

for one_filename in glob.glob(f'{dirname}/*'):
    try:
        m = hashlib.md5()
        m.update(one_filename.encode())
        output[one_filename] = m.hexdigest()
    except:
        pass

Perhaps...

for one_filename in glob.glob(f'{dirname}/*'):
    try:
        with open(one_filename, 'rb') as file:
            data = file.read()
            output[one_filename] = hashlib.md5(data).hexdigest()
    except:
        pass

Miguel-Ojeda avatar Feb 05 '22 13:02 Miguel-Ojeda