# Generate a Clean Folder Tree of Any Project with Python

> Run list_structure.py on a project and it writes FolderFileStructure.txt: a tree with branch connectors, directories first, noise folders excluded, and a file count summary.

URL: https://thuyavan.netlify.app/scripts/repository-tree-generator
Updated: 2026-10-07

## Problem
Explaining the architecture of a nested project through a file explorer is hard, and hand-formatting tree structures for documentation is slow and error-prone.

## Solution
A CLI tool that walks a root directory with recursive depth-first search, skips noise folders and draws a connector-style tree.

## Result
A professional FolderFileStructure.txt that maps any codebase in seconds.

## Input
- Root folder (current directory by default, or --root path)
- Optional --exclude rules

## Output
- FolderFileStructure.txt at the root

## Optional output
- Timestamped header and absolute root path
- Final count of directories and files processed

## System flow
CLI / argparse (--root · --exclude) -> DFS walk (Recursive traversal) -> Exclusion engine (20+ default junk names) -> Tree renderer (├── └── │ connectors) -> FolderFileStructure.txt (Tree + summary)

## How it works
- **Intelligent exclusions:** Ignores .git, node_modules, .venv, __pycache__, .DS_Store and 20+ more.
- **Recursive visualisation:** A walk function draws a readable branch hierarchy.
- **Smart sorting:** Directories first, case-insensitive order for consistent output.
- **CLI flexibility:** Override the root or add custom exclusions from the command line.

## Configuration
- `DEFAULT_EXCLUDES`: Pre-set for Python, JavaScript and Flutter projects.
- `--root`: Project folder to map.
- `--exclude`: Repeatable flag to add extra ignored names.

## How to run
Current directory:

    python list_structure.py
Specific project:

    python list_structure.py --root "C:/Path/To/Your/Project"
Custom exclusions:

    python list_structure.py --exclude "temp_logs" --exclude "secrets"

## Impact
- Instant technical onboarding for new developers.
- Output is ready for READMEs, TRDs and architecture reports.
- Perfect project-map context to hand to AI coding assistants.
- A permanent audit record of the project state.

## FAQ
**How do I print a folder structure as a tree in Python?**
The script walks the directory recursively (depth-first) and draws branch connectors, writing the result to FolderFileStructure.txt.

**Which folders does it ignore?**
More than 20 defaults such as .git, node_modules, .venv, __pycache__ and .DS_Store. Add more with repeated --exclude flags.

**Is the output useful for AI coding assistants?**
Yes. A compact project map gives tools like ChatGPT or Claude the architecture context in one paste.

