-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub-tree.py
More file actions
26 lines (23 loc) · 959 Bytes
/
github-tree.py
File metadata and controls
26 lines (23 loc) · 959 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
import os
def print_filtered_tree(startpath, prefix=""):
entries = sorted(os.listdir(startpath))
# Filter out hidden folders and files except .py/.ipynb files
filtered = []
for e in entries:
if e.startswith('.'):
continue # skip hidden files and folders like .git
full_path = os.path.join(startpath, e)
if os.path.isdir(full_path):
filtered.append(e)
elif e.endswith('.py') or e.endswith('.ipynb'):
filtered.append(e)
for i, entry in enumerate(filtered):
path = os.path.join(startpath, entry)
connector = "├── " if i < len(filtered) - 1 else "└── "
print(prefix + connector + entry)
if os.path.isdir(path):
extension = "│ " if i < len(filtered) - 1 else " "
print_filtered_tree(path, prefix + extension)
root_folder = os.path.basename(os.getcwd())
print(root_folder)
print_filtered_tree('.')