-
Notifications
You must be signed in to change notification settings - Fork 1
/
file_label.py
113 lines (94 loc) · 2.72 KB
/
file_label.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import csv
import os
import shutil
count = 0
cwd = "/home/ieshaan/Desktop/Python/Misc/Document Classification Exercise/crop_jpg/"
f1 = "/home/ieshaan/Desktop/Python/Misc/Document Classification Exercise/f1/"
f2 = "/home/ieshaan/Desktop/Python/Misc/Document Classification Exercise/f2/"
f3 = "/home/ieshaan/Desktop/Python/Misc/Document Classification Exercise/f3/"
f4 = "/home/ieshaan/Desktop/Python/Misc/Document Classification Exercise/f4/"
f5 = "/home/ieshaan/Desktop/Python/Misc/Document Classification Exercise/f5/"
f6 = "/home/ieshaan/Desktop/Python/Misc/Document Classification Exercise/f6/"
all_files = []
for i in os.listdir(cwd):
all_files.append(i)
all_files.sort()
var = 'label'
f1_data = []
for i in range(500):
path_of_file = cwd + all_files[i]
new_loc_of_file = f1 + all_files[i]
shutil.move(path_of_file,new_loc_of_file)
temp = []
temp.append(all_files[i])
temp.append(var)
f1_data.append(temp)
with open(f1+'data.csv','w') as csvFile:
writer = csv.writer(csvFile)
writer.writerows(f1_data)
csvFile.close()
f2_data = []
for i in range(500,1000):
path_of_file = cwd + all_files[i]
new_loc_of_file = f2 + all_files[i]
shutil.move(path_of_file,new_loc_of_file)
temp = []
temp.append(all_files[i])
temp.append(var)
f2_data.append(temp)
with open(f2+'data.csv','w') as csvFile:
writer = csv.writer(csvFile)
writer.writerows(f2_data)
csvFile.close()
f3_data = []
for i in range(1000,1500):
path_of_file = cwd + all_files[i]
new_loc_of_file = f3 + all_files[i]
shutil.move(path_of_file,new_loc_of_file)
temp = []
temp.append(all_files[i])
temp.append(var)
f3_data.append(temp)
with open(f3+'data.csv','w') as csvFile:
writer = csv.writer(csvFile)
writer.writerows(f3_data)
csvFile.close()
f4_data = []
for i in range(1500,2000):
path_of_file = cwd + all_files[i]
new_loc_of_file = f4 + all_files[i]
shutil.move(path_of_file,new_loc_of_file)
temp = []
temp.append(all_files[i])
temp.append(var)
f4_data.append(temp)
with open(f4+'data.csv','w') as csvFile:
writer = csv.writer(csvFile)
writer.writerows(f4_data)
csvFile.close()
f5_data = []
for i in range(2000,2500):
path_of_file = cwd + all_files[i]
new_loc_of_file = f5 + all_files[i]
shutil.move(path_of_file,new_loc_of_file)
temp = []
temp.append(all_files[i])
temp.append(var)
f5_data.append(temp)
with open(f5+'data.csv','w') as csvFile:
writer = csv.writer(csvFile)
writer.writerows(f5_data)
csvFile.close()
f6_data = []
for i in range(2500,3000):
path_of_file = cwd + all_files[i]
new_loc_of_file = f6 + all_files[i]
shutil.move(path_of_file,new_loc_of_file)
temp = []
temp.append(all_files[i])
temp.append(var)
f6_data.append(temp)
with open(f6+'data.csv','w') as csvFile:
writer = csv.writer(csvFile)
writer.writerows(f6_data)
csvFile.close()