Skip to content

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

@Miguel-Ojeda

Description

@Miguel-Ojeda

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions