-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorkOnKey.py
More file actions
32 lines (25 loc) · 1.04 KB
/
WorkOnKey.py
File metadata and controls
32 lines (25 loc) · 1.04 KB
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
import sys, os, hashlib
def fileList(highest_directory):
file_list = []
for path, subdirs, files in os.walk(highest_directory):
for name in files:
file_list.append(os.path.join(path, name))
return file_list
def nameList(highest_directory):
name_list = []
for path, subdirs, files in os.walk(highest_directory):
for name in files:
name_list.append(name)
#print name # Can this be used as a key for the dictionary (i.e. is it unique to each run?)
return name_list
def hashing(inp_file, hash_algo, blocks_to_load=65536):
with open(inp_file, "rb") as fl:
for chunk in iter(lambda: fl.read(blocks_to_load), b""):
hash_algo.update(chunk)
return hash_algo.hexdigest()
folder_h = "C:\\Users\\Sara\\Google Drive\\MScProjectExtras\\ExtraDataForDatabase\\160224_M02641_0082_000000000-ALPHF\\"
hashdict = {}
names = nameList(folder_h)
for i, file_name in enumerate(fileList(folder_h)):
hashdict.update({names[i]:hashing(file_name, hashlib.sha256())})
print hashdict