-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathreadfile.py
32 lines (29 loc) · 1.1 KB
/
readfile.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
import os
folder = '/data/jian.liang/datasets/OfficeHome/'
domains = os.listdir(folder)
domains.sort()
for d in range(len(domains)):
dom = domains[d]
if os.path.isdir(os.path.join(folder, dom)):
dom_new = dom.replace(" ","_")
print(dom, dom_new)
os.rename(os.path.join(folder, dom), os.path.join(folder, dom_new))
classes = os.listdir(os.path.join(folder, dom_new))
classes.sort()
# print(classes)
f = open(dom_new[0] + "_list.txt", "w")
for c in range(len(classes)):
cla = classes[c]
cla_new = cla.replace(" ","_")
print(cla, cla_new)
os.rename(os.path.join(folder, dom_new, cla), os.path.join(folder, dom_new, cla_new))
files = os.listdir(os.path.join(folder, dom_new, cla_new))
files.sort()
# print(files)
for file in files:
file_new = file.replace(" ","_")
os.rename(os.path.join(folder, dom_new, cla_new, file), os.path.join(folder, dom_new, cla_new, file_new))
print(file, file_new)
print('{:} {:}'.format(os.path.join(folder, dom_new, cla_new, file_new), c))
f.write('{:} {:}\n'.format(os.path.join(folder, dom_new, cla_new, file_new), c))
f.close()