Python · Developer Tooling

Generate a Clean Folder Tree of Any Project with Python

TL;DR

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.

Updated 1 min read

PythonargparseRecursive DFS

Abstract

The 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.

The solution

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

The result

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

Input & Output

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 Diagram

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

OptionPurpose
DEFAULT_EXCLUDESPre-set for Python, JavaScript and Flutter projects.
--rootProject folder to map.
--excludeRepeatable 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 & Benefits

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.

Screenshots

1/2 Running the generator
2/2 Generated tree with summary counts

Frequently Asked Questions

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.

Related

© 2026 Thuyavan Sivarasa. Script code is MIT licensed.