-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.py
More file actions
47 lines (36 loc) · 1.11 KB
/
data.py
File metadata and controls
47 lines (36 loc) · 1.11 KB
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
import os
def get_files(dirs: list[list[str]], path=['data'], ext=''):
files = []
for f in os.listdir(os.path.join(*path)):
p = os.path.join(*path, f)
if os.path.isfile(p) and p.endswith(ext):
files.append(p)
if len(dirs) == 0:
return files
for d in dirs[0]:
path.append(d)
p = os.path.join(*path)
if os.path.isdir(p):
files.extend(get_files(dirs[1:], path=path, ext=ext))
path.pop()
return files
def expand_dir_tree(dirs: list[list[str]], path: str | list[str] = 'data'):
if not isinstance(path, list):
path = list([path])
paths = []
if len(dirs) != 0:
for d in dirs[0]:
path.append(d)
paths.extend(expand_dir_tree(dirs[1:], path))
path.pop()
else:
paths.append(list(path))
return paths
if __name__ == '__main__':
options = [['automatic', 'manual'],
['luigi-circuit', 'moo-moo-meadows'],
['mario'],
['karts', 'bikes'],
['classic']]
f = expand_dir_tree(options)
print(f)