Skip to main content

Convert text directory trees (struct.txt) into real folders and files.

Project description

📘 tree2cmd

tree2cmd is a lightweight Python tool that instantly converts a text-based directory tree (like struct.txt) into real folders and files. It supports both ASCII and Unicode tree formats—including emojis—and generates safe shell commands using mkdir -p and touch.

It is perfect for quickly bootstrapping new projects, sharing folder layouts, automating templates, teaching directory structures, and turning documentation examples into actual directories.

Convert text-based directory trees into real folders and files.

PyPI Version Python Versions License: MIT Tests Platform Build Downloads


📑 Table of Contents


✨ Overview

tree2cmd converts text-based directory trees (ASCII/Unicode) like:

Project/
├── src/
│   └── main.py
└── README.md

into actual folders and files using shell commands:

mkdir -p "Project/"
mkdir -p "Project/src/"
touch "Project/src/main.py"
touch "Project/README.md"

Perfect for:

✔ Rapid project scaffolding ✔ Teaching directory layouts ✔ DevOps automation ✔ Reproducible project templates ✔ Converting documentation examples into real directories

Fully tested across ASCII trees, Unicode trees, emoji trees, and mixed indentation styles.


🚀 Quick Start

1. Make struct.txt:

Project/
  src/
    main.py
  README.md

2. Convert to commands:

tree2cmd struct.txt

3. Actually create them:

tree2cmd struct.txt --run

📦 Installation

Stable release:

pip install tree2cmd

Latest development version:

pip install git+https://github.com/ajmanjoma/tree2cmd.git

📂 Example Input → Output

Input:

📦 App/
  backend/
    api.py
  README.md

Output:

mkdir -p "📦 App/"
mkdir -p "📦 App/backend/"
touch "📦 App/backend/api.py"
touch "📦 App/README.md"

This works for any:

  • ASCII tree
  • Unicode tree
  • Emoji directory
  • Mixed indentation
  • Minimal struct format
  • Multi-root trees

🔧 Usage Guide

Dry run (recommended):

tree2cmd struct.txt

Execute commands:

tree2cmd struct.txt --run

Save script:

tree2cmd struct.txt --save setup.sh

Use standard input:

cat struct.txt | tree2cmd --stdin

Show tree instead of commands:

tree2cmd struct.txt --tree

Disable logs:

tree2cmd struct.txt --no-verbose

🧠 How It Works

tree2cmd uses a 3-stage pipeline:


1️⃣ Parsing

Handles:

  • ASCII trees (|-, +--, etc.)
  • Unicode trees (├──, , └──)
  • Mixed whitespaces and unexpected characters
  • Emojis and non-ASCII folder names
  • Multi-root directories
  • Deep nesting

Uses indentation and tree symbols to infer hierarchy.


2️⃣ Classification

Folder detection rules:

  • Ends with /folder
  • Contains .file
  • Next line is more indented → folder
  • Otherwise → file

3️⃣ Command Generation

Folders → mkdir -p Files → touch

All paths:

  • Are normalized
  • Are quoted
  • Escape shell-sensitive characters

📚 Documentation

Topic File
Usage Guide docs/usage.md
CLI Options docs/cli.md
Parser Details docs/parser.md
API Reference docs/api.md
FAQ docs/faq.md
Contributing docs/contributing.md
Changelog docs/changelog.md

🧪 Running Tests

Run all tests:

python -m unittest discover -s tests -p "test*.py" -v

With Makefile:

make test

Coverage: 100% (parser + CLI)


🔄 Versioning & Publishing

1. Bump version automatically:

make version patch
# or minor / major

2. Build:

python -m build

3. Upload to PyPI:

twine upload dist/*

4. GitHub Actions (automatic):

  • On tag push → build + test + publish
  • On PR → run tests

Workflow located at:

.github/workflows/python-publish.yml

🤝 Contributing

All contributions are welcome!

  1. Fork repo
  2. Create a branch
  3. Add tests for new features
  4. Run tests
  5. Open PR

See full guide: 📄 docs/contributing.md


🗺️ Roadmap

  • Windows PowerShell support
  • JSON/YAML → tree converter
  • VSCode extension
  • GUI visualizer
  • Template engine (copy boilerplate files)

📄 License

MIT License — free for personal & commercial use.


👤 Author

Antony Joseph Mathew 📧 antonyjosephmathew1@gmail.com 🌐 GitHub: https://github.com/ajmanjoma/tree2cmd

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tree2cmd-0.2.1.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tree2cmd-0.2.1-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file tree2cmd-0.2.1.tar.gz.

File metadata

  • Download URL: tree2cmd-0.2.1.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for tree2cmd-0.2.1.tar.gz
Algorithm Hash digest
SHA256 107c6f7445e3e85c22316c67c68774cfc752695651ece57ffad42e804695199d
MD5 0efa0000b19e282927d72f0100aee2f0
BLAKE2b-256 11ee779c529ea9f98022b255c93027d99a87f535aeb37c336845b6f78316cd9a

See more details on using hashes here.

File details

Details for the file tree2cmd-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: tree2cmd-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for tree2cmd-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ff7298db8796de32e50efc9300aec5be80c3530cf876abb7f5d5ac729ab93279
MD5 d6cbddd742e7299fcdccb2702216fbd1
BLAKE2b-256 9d64798cfb635efa3319beefc607cb573b1dd71f8f401b7bdf8b69c262078e9c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page