-
Notifications
You must be signed in to change notification settings - Fork 2
/
upload_controller.py
48 lines (34 loc) · 1.31 KB
/
upload_controller.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
'''
Hey Pim, try fiddling with this. from what I can make of it it accesses the directory using os.walk
which should return the file names
os.walk returns the root directory, list of directories, and the files found in those directors in a tuple.
We only want the 3rd item, the files, which is why there are two loops (but you already know that).
'''
import os
import mysql.connector
def main():
pass
if __name__ == '__main__':
main()
cnx = mysql.connector.connect()
cursor = cnx.cursor()
#change to directory to the one holding the malware files
for root, dir, files in os.walk("L:\Preservation", topdown=True):
for name in files:
#we don't really need the join function.
#it might work if we just use something like this :
#fname = name
fname = os.path.join(root, name)
print(fname)
sql = "INSERT INTO malware VALUES('" + (fname) + "')"
cursor.execute(sql)
cnx.commit()
# print(os.path.join(root, name))
#for name in dirs:
# print(os.path.join(root, name))
cnx.close()
'''
The mysql db is set up so the id number auto increments when something is put in. So if this works we'll have the
name and id number of all the malware. you can manually enter the rest, or we could do more complex things to figure out
the rest of the info.
'''