Walk through a Directory creating SHA Hashes of each file path
| 1 2 3 4 5 6 7 8 9 | import sha
import os
def createsha(directory):
    """Walk through a Directory creating Sha Hashes of each file path"""
    for root, dirs, files in os.walk(str(directory)):
        for name in files:
            filepath = os.path.join(root, name)
            value = sha.new(filepath).hexdigest()
            print value
 | 

 Download
Download Copy to clipboard
Copy to clipboard
This example is misleading. The comment in the function states that it takes checksums of each file, but the function itself only takes checksums of the file paths found in a directory not their contents.
Here is a small modification that will also make the output compatible with 'sha1sum -c' :-
I made a more robust version of the previous commenters code if anyone reading this is interested:
http://akiscode.com/articles/sha-1directoryhash.shtml