import os, sys sys.stdout.reconfigure(encoding='utf-8') root = r'D:\code\crm-api-docs' for dirpath, dirnames, filenames in os.walk(root): dirnames[:] = [d for d in dirnames if d not in ('.git', 'node_modules', '.vscode')] rel = os.path.relpath(dirpath, root) depth = 0 if rel == '.' else rel.count(os.sep) + 1 if depth <= 2: indent = ' ' * depth name = '.' if rel == '.' else os.path.basename(dirpath) print(f'{indent}{name}/ ({len(filenames)} files)')