A command-line tool that generates directory structures and files from ASCII tree specifications.
treegen takes a text file containing an ASCII tree representation and creates the corresponding directory structure and files on your filesystem. It's useful for quickly setting up project templates, scaffolding applications, or creating test directory structures.
- ASCII Tree Parsing: Supports various tree connector symbols (
├──
,└──
,│
,|--
,\--
, etc.) - Flexible Indentation: Configurable indent width (default: 4 spaces)
- Dry Run Mode: Preview what would be created without actually creating files
- Automatic Directory Inference: Automatically detects directories based on tree structure
- Cross-Platform: Works on Windows, macOS, and Linux
- Go 1.16 or later
git clone <repository-url>
cd treegen
go build -o treegen main.go
./treegen [-width N] [-dry] <spec-file>
-width N
: Set the number of spaces per indent level (default: 4)-dry
: Dry run mode - show what would be created without creating files<spec-file>
: Path to the specification file containing the ASCII tree
Create a spec file project.spec
:
my-project/
├── src/
│ ├── main.go
│ └── utils.go
├── docs/
│ └── README.md
├── tests/
│ └── test.go
└── Makefile
Run TreeGen:
./treegen project.spec
This will create:
my-project/
├── src/
│ ├── main.go
│ └── utils.go
├── docs/
│ └── README.md
├── tests/
│ └── test.go
└── Makefile
Preview what would be created:
./treegen -dry project.spec
Output:
[dry] mkdir -p my-project
[dry] mkdir -p my-project/src
[dry] touch my-project/src/main.go
[dry] touch my-project/src/utils.go
[dry] mkdir -p my-project/docs
[dry] touch my-project/docs/README.md
[dry] mkdir -p my-project/tests
[dry] touch my-project/tests/test.go
[dry] touch my-project/Makefile
For spec files with different indentation:
./treegen -width 2 project.spec
You can also specify simple file paths:
a/b/c/d/e.txt
This creates the directory structure a/b/c/d/
and the file e.txt
inside it.
treegen supports various ASCII tree formats:
project/
├── src/
│ ├── main.go
│ └── utils.go
└── docs/
└── README.md
project/
|-- src/
| |-- main.go
| \-- utils.go
\-- docs/
\-- README.md
project/
├── src/
│ ├── main.go
│ └── utils.go
└── docs/
└── README.md
Directories are automatically detected in two ways:
- Explicit: Names ending with
/
are treated as directories - Implicit: Items that have children (nodes with greater depth) are treated as directories
TreeGen recognizes these connector symbols:
├──
(branch with continuation)└──
(branch end)│
(vertical line)|--
(alternative branch)\--
(alternative branch end)├─
(short branch)└─
(short branch end)- And various Unicode alternatives
- File Already Exists: TreeGen will skip existing files and report them
- Permission Errors: Clear error messages for permission issues
- Invalid Spec Files: Graceful handling of malformed input
- Project Scaffolding: Quickly set up new project structures
- Testing: Create test directory structures for unit tests
- Documentation: Generate example directory layouts
- Templates: Create reusable project templates
- Development: Set up development environments quickly
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
webapp/
├── public/
│ ├── index.html
│ ├── css/
│ │ └── style.css
│ └── js/
│ └── app.js
├── src/
│ ├── components/
│ │ ├── Header.js
│ │ └── Footer.js
│ └── utils/
│ └── helpers.js
├── tests/
│ └── app.test.js
├── package.json
└── README.md
myapp/
├── cmd/
│ └── myapp/
│ └── main.go
├── internal/
│ ├── handler/
│ │ └── handler.go
│ └── service/
│ └── service.go
├── pkg/
│ └── utils/
│ └── utils.go
├── go.mod
└── README.md