# Tree Viewer
An interactive CLI tool that displays directory structures with beautiful tree visualization. No command-line arguments required — just run and answer prompts.
Features
| Feature | Description |
|---|---|
| Interactive | No CLI args needed, prompts guide you |
| Customizable Depth | Set how many levels deep to display |
| Hidden Files | Toggle visibility with Yes/No |
| Emoji Tree | Visual folder structure with icons |
| Standalone .exe | PyInstaller packaging supported |
Usage
bash
python tree_viewer.pyInteractive Prompts
code
--- Select Root Directory ---
Enter the path to the folder you want to display: C:\MyProject
--- Tree Depth ---
How many levels deep should the tree go? (1-10): 3
--- Hidden Files ---
Show hidden files? (Y/N): Y
📂 MyProject/
├── 📁 src/
│ ├── 📄 main.py
│ └── 📁 utils/
│ └── 📄 helpers.py
├── 📁 tests/
│ └── 📄 test_main.py
└── 📄 README.mdCore Implementation
python
import os
from pathlib import Path
def display_tree(root_path: str, max_depth: int, show_hidden: bool):
root = Path(root_path)
def walk_tree(path: Path, prefix: str = "", depth: int = 0):
if depth > max_depth:
return
# Get entries
try:
entries = sorted(path.iterdir(), key=lambda x: (not x.is_dir(), x.name))
except PermissionError:
return
for i, entry in enumerate(entries):
# Skip hidden files if not requested
if not show_hidden and entry.name.startswith('.'):
continue
is_last = i == len(entries) - 1
connector = "└── " if is_last else "├── "
# Emoji based on type
icon = "📁" if entry.is_dir() else "📄"
print(f"{prefix}{connector}{icon} {entry.name}")
# Recurse for directories
if entry.is_dir():
new_prefix = prefix + (" " if is_last else "│ ")
walk_tree(entry, new_prefix, depth + 1)
print(f"📂 {root.name}/")
walk_tree(root, "", 1)PyInstaller Packaging
bash
pyinstaller --onefile --name "TreeViewer" tree_viewer.pyOutput: dist/TreeViewer.exe — runs on any Windows machine without Python.
Use Cases
- Project overview: Visualize folder structure for documentation
- Code reviews: Understand project layout quickly
- File organization: Debug directory structure issues
- Sharing: Export tree view for team communication
Architecture Feedback
Spotted a potential optimization or antipattern? Let me know.