-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbonsai.py
More file actions
29 lines (24 loc) · 818 Bytes
/
bonsai.py
File metadata and controls
29 lines (24 loc) · 818 Bytes
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
import os
import sys
def print_tree(start_path, prefix=""):
try:
items = sorted(os.listdir(start_path))
except PermissionError:
print(prefix + "└── [Permission Denied]")
return
for i, name in enumerate(items):
path = os.path.join(start_path, name)
connector = "└── " if i == len(items) - 1 else "├── "
print(prefix + connector + name)
if os.path.isdir(path):
extension = " " if i == len(items) - 1 else "│ "
print_tree(path, prefix + extension)
def main():
if len(sys.argv) > 1:
root_dir = sys.argv[1]
else:
root_dir = "." # current directory
print(f"\nDirectory tree for: {os.path.abspath(root_dir)}\n")
print_tree(root_dir)
if __name__ == "__main__":
main()