-
Notifications
You must be signed in to change notification settings - Fork 43
/
get_filelist_recurrent.py
37 lines (30 loc) · 1.15 KB
/
get_filelist_recurrent.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
import os
import pdb
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--folder') # path data folders
parser.add_argument('--output') # path to save as txt
parser.add_argument('--postfix', default=".jpg") # file
opt = parser.parse_args()
save_name = opt.output #"imagenet_image_list.txt"
path_data = opt.folder #'../../data/datasets/ILSVRC12_image_train'
file_postfix =opt.postfix #".JPEG"
path_data = os.path.abspath(path_data)
if path_data.endswith("/"): path_data=path_data[:-1]
if not file_postfix.startswith("."): file_postfix="."+file_postfix
folders = os.listdir(path_data)
file_list = []
def get_filename(path, list_save):
print(len(file_list))
if os.path.isdir(path):
for folder in os.listdir(path):
get_filename(os.path.join(path, folder), list_save)
elif path.endswith(file_postfix):
_path = path
_path = _path.replace(path_data+"/", "")
list_save.append(_path)
_path = path.replace(file_postfix, "")
get_filename(path_data, file_list)
file_list = list(map(lambda x: x.replace(path_data+"/", "")+'\n', file_list))
with open(save_name, "w") as f:
f.writelines(file_list)