-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmd5all.py
More file actions
35 lines (31 loc) · 795 Bytes
/
md5all.py
File metadata and controls
35 lines (31 loc) · 795 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""
Script for mass MD5'ing a directory. Run and automagicilly receive your output CSV <default == output.md5>
version 0.0.0.0.2
@gimbi
"""
import os, shutil, hashlib
PATH = "."
OUTPUT_FILE = "output.md5"
def md5_file(f, block_size = 2**20):
"""
Generates MD5 hash. Credited to Laurent Luce http://www.laurentluce.com/
"""
md5 = hashlib.md5()
with open(f,'rb') as file_:
while 1:
data = file_.read(block_size)
if not data: break
md5.update(data)
return md5.hexdigest()
def main():
"""
Whatevs, yo.
"""
file_list = os.listdir(PATH)
with open(OUTPUT_FILE, 'w') as output_file:
for file_name in file_list:
try: output_file.write(md5_file(file_name) + ',' + file_name + '\n')
except:
print "File %s skipped" % (file_name)
if __name__ == '__main__':
main()