Created
January 6, 2016 13:08
-
-
Save wadeschulz/4406656d920e64dc794a to your computer and use it in GitHub Desktop.
Python script to generate md5 and sha1 hashes for files of given extension in a directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hashlib, os | |
def hashfile(afile, hasher, blocksize=65536): | |
buf = afile.read(blocksize) | |
while len(buf) > 0: | |
hasher.update(buf) | |
buf = afile.read(blocksize) | |
return hasher.hexdigest() | |
path = raw_input("Enter directory to scan: ") | |
extension = raw_input("Enter file extension: ") | |
print "File\tmd5\tsha1" | |
os.chdir(path) | |
for filename in os.listdir(path): | |
if filename.endswith(extension): | |
print filename + "\t" + hashfile(open(filename, 'rb'), hashlib.md5()) + "\t" + hashfile(open(filename, 'rb'), hashlib.sha1()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment