0

I need to create a program that creates hash signatures for each file in my directory. I need the output to contain the filename and hash next to it.

This is the code I have so far and all it is doing is giving me the hashes.

import os, hashlib

path = "/home/ec2-user/environment"

for filename in os.listdir(path):
    if not os.path.isdir(filename):

        hasher = hashlib.md5()
    with open('39802.jpeg', 'rb') as afile:
        buf = afile.read()
    hasher.update(buf)
    print(hasher.hexdigest())
tkausl
  • 13,686
  • 2
  • 33
  • 50
  • You don't print the filename – tkausl Apr 06 '18 at 00:14
  • `print("{:<20} {}".format(filename, hasher.hexdigest()))` ? Also, why are loading a fixed name file? You should use `filename` in your `open(...)` call, plus you should fix the indentation and add `continue` for the `os.path.isdir()` condition. – zwer Apr 06 '18 at 00:19

0 Answers0