-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtree.py
60 lines (46 loc) · 1.11 KB
/
tree.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
from pathlib import Path
tree_str = ''
ignore_path = [
".pio",
".git",
".vscode",
".idea"
]
ignore_file = [
"gitattributes",
"gitignore",
"yml",
"travis",
"DS_Store",
]
def is_ignore_path(path):
if path in ignore_path:
return True
else:
return False
def is_ignore_file(filename):
# print(filename)
out = filename.split('.')
# print(out)
try:
if out[1] in ignore_file:
return True
else:
return False
except IndexError:
pass
def generate_tree(pathname, n=0):
global tree_str
if pathname.is_file():
if not is_ignore_file(pathname.name):
tree_str += ' |' * n + '-' * 4 + pathname.name + '\n'
elif pathname.is_dir():
# print(pathname)
if not is_ignore_path(pathname.name):
tree_str += ' |' * n + '-' * 4 + \
str(pathname.relative_to(pathname.parent)) + '\n'
for cp in pathname.iterdir():
generate_tree(cp, n + 1)
if __name__ == '__main__':
generate_tree(Path.cwd())
print(tree_str)