-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBreak Files.py
92 lines (54 loc) · 1.29 KB
/
Break Files.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import os
import hashlib
import pickle
def save(path):
def allPatches(path):
tree = os.walk(path)
Patches = []
for i in tree:
Path = i[0]
Files = i[2]
for File in Files:
Patches.append(Path + "/" + File)
return Patches
dic = {}
all = allPatches(path)
for index, i in enumerate(all):
print (index * 1.0 / len(all)) * 100, "%"
dic[i] = hashlib.md5(open(i,'rb').read()).hexdigest()
filename = path.replace("/", "->") + ".bd"
file = open(filename,'wr')
pickle.dump(dic,file)
file.close()
def test(path):
def load(path):
filename = path.replace("/", "->") + ".bd"
file = open(filename, "rb")
dic = pickle.load(file)
file.close()
return dic
def main_test(dic):
Eror = False
index = 0
for file, hash in dic.iteritems():
print (index * 1.0 / len(dic)) * 100, "%"
byte = None
try:
byte = open(file,'rb').read()
except IOError:
Eror = True
print "No such file", file
if not byte is None:
if hashlib.md5(byte).hexdigest() != hash:
Eror = True
print "File ", file," damaged"
index += 1
if Eror:
print "Completed with errors"
else:
print "Completed without errors"
dic = load(path)
main_test(dic)
path = "" # You path
#save(path) # for save hash all files
#test(path) # for check hask sum