'MD5 Hashing all files in a directory

I am trying to make a program that loops over all my files in a directory and make then all md5 hash codes.

import hashlib, os, sys
for root, dirs,files in os.walk("C:\Users\Matt\AppData\NewFolder", topdown=True):
    for name in files:
        #print(os.path.join(root, name))
FileName = (os.path.join(root, name))

hasher = hashlib.md5()
with open(str(FileName), 'rb') as afile:
    buf = afile.read()
    hasher.update(buf)
print(hasher.hexdigest())

If someone would be willing to help me out that would be great.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source