1
# http://akiscode.com/articles/sha-1directoryhash.shtml
2
# Copyright (c) 2009 Stephen Akiki
3
# MIT License (Means you can do whatever you want with this)
4
# See http://www.opensource.org/licenses/mit-license.php
6
# -1 -> Directory does not exist
7
# -2 -> General error (see stack traceback)
9
def GetHashofDirs(dirs, verbose=0):
11
SHAhash = hashlib.sha1()
14
for directory in dirs:
15
if not os.path.exists (directory):
17
for files in os.listdir(directory):
19
print 'Hashing', files
20
filepath = os.path.join(directory,files)
22
f1 = open(filepath, 'rb')
24
# You can't open the file for some reason
29
# Read file in as little chunks
32
SHAhash.update(hashlib.sha1(buf).hexdigest())
37
# Print the stack traceback
41
return SHAhash.hexdigest()
42
#print GetHashofDirs('My Documents', 1)