Python Scan Struktur Folder
Berikut Kodenya.
# python scan_structure.py /path/to/my-next-app
import os
IGNORED_FOLDERS = {"node_modules", ".git", ".next", "__pycache__"}
INDENT = "│ "
def scan_folder(path: str, prefix=""):
items = sorted(os.listdir(path))
items = [item for item in items if item not in IGNORED_FOLDERS and not item.startswith(".")]
for i, item in enumerate(items):
full_path = os.path.join(path, item)
is_last = (i == len(items) - 1)
connector = "└── " if is_last else "├── "
print(prefix + connector + item)
if os.path.isdir(full_path):
new_prefix = prefix + (" " if is_last else INDENT)
scan_folder(full_path, new_prefix)
if __name__ == "__main__":
import sys
if len(sys.argv) != 2:
print("Usage: python scan_structure.py <path_to_project>")
else:
project_path = sys.argv[1]
if os.path.isdir(project_path):
print(os.path.basename(project_path) + "/")
scan_folder(project_path)
else:
print("Invalid path:", project_path)