-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcvtfilename.py
38 lines (30 loc) · 1.1 KB
/
cvtfilename.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
import os
from tqdm import tqdm
def renamefile(filename):
"""
One can use this file to convert filename path
"""
new_data_list = []
with open(filename, 'r') as f:
data_list = f.read().split('\n')
print('Generating new data list..')
for data in tqdm(data_list):
if len(data) == 0:
continue
data_info = data.split(' ')
#data_info[0] = data_info[0].replace('jpg', 'png')
#data_info[1] = data_info[1].replace('jpg', 'png')
for it, name in enumerate(data_info):
data_info[it] = '/'.join(name.split('/')[1:])
if data_info[2].find('extras') == -1:
new_data_list.append(' '.join(data_info))
with open(filename, 'w') as f:
print('writing new data names..')
for it, data in tqdm(enumerate(new_data_list)):
if len(data) == 0:
continue
if it == len(new_data_list)-1:
f.write(data)
else:
f.write(data+'\n')
print('Done.')