treekyt

Crates.iotreekyt
lib.rstreekyt
version0.1.2
created_at2025-12-31 04:45:24.63294+00
updated_at2026-01-01 04:49:03.302919+00
descriptionRecreate directory and file structure from `tree` command output
homepagehttps://github.com/k0max/treekyt
repositoryhttps://github.com/k0max/treekyt
max_upload_size
id2013914
size39,884
Ziwen Liao (K0max)

documentation

README

treekyt

๐ŸŒฒ Reconstruct directory and file structures from tree command output โ€” instantly.

treekyt parses textual tree representations (like those from Unix tree or Windows tree /F) and recreates the exact nested directory and file structure on your filesystem. All files are created empty; directories are inferred automatically.

Easy for:

  • Rebuilding project skeletons from documentation or chat logs
  • Sharing folder layouts without transferring actual files
  • Bootstrapping new projects from a tree command output (e.g., from text copied from screenshots)

๐Ÿš€ Installation

You need Rust installed.

cargo install treekyt

๐Ÿ“ฆ Usage

From stdin (most common)

# Unix/Linux/macOS
tree -F my_project | treekyt

# Or paste any valid tree structure
echo 'myapp/
โ”œโ”€โ”€ src/
โ”‚   โ””โ”€โ”€ main.rs
โ””โ”€โ”€ README.md' | treekyt

From a file

treekyt --file structure.txt

Overwrite existing files

By default, treekyt will skip files that already exist. To overwrite them, use the --overwrite flag:

treekyt --file structure.txt --overwrite

With comments (AI-generated trees)

When an AI assistant generates a file tree, it often includes comments. treekyt automatically ignores them:

echo 'myapp # my application
โ”œโ”€โ”€ src # source code
โ”‚   โ”œโ”€โ”€ lib.rs # library code
โ”‚   โ””โ”€โ”€ bin # binary
โ”‚       โ””โ”€โ”€ main.rs
โ”œโ”€โ”€ Cargo.toml # manifest
โ””โ”€โ”€ README.md # documentation' | treekyt

Comments (everything after # on each line) are stripped before processing, so the above creates the same structure as the uncommented version.

Help & version

treekyt --help
treekyt --version

Sample --help output:

Recreate directory and file structure from `tree` command output

Usage: treekyt [OPTIONS]

Options:
  -f, --file <FILE>      Read input from a file instead of stdin
  -o, --overwrite        Overwrite existing files (default: off)
  -h, --help             Print help
  -V, --version          Print version

๐Ÿ’ป Platform-Specific Notes

Unix-like Systems (tree)

Use tree -F to append / to directory names โ€” this improves parsing accuracy:

tree -F > structure.txt
treekyt -f structure.txt

Windows (tree /F)

On Windows, use tree /F to include files in the output:

C:\> tree /F > structure.txt
C:\> treekyt -f structure.txt

โœ… Example Windows tree /F output:

Folder PATH listing for volume Windows
Volume serial number is 1234-5678
C:.
โ”œโ”€โ”€โ”€docs
โ”‚       notes.txt
โ””โ”€โ”€โ”€src
        main.rs
        utils.rs

โ†’ treekyt automatically:

  • Skips header lines (e.g., "Folder PATH listing", volume info)
  • Treats C:\. or C:. as root (uses current working directory as base)
  • Infers that docs/ and src/ are directories because they contain nested files

๐Ÿ”” Tip: Windows tree /F does not mark directories with /, so treekyt relies entirely on nesting depth to infer folders. Ensure your output includes files under directories โ€” otherwise, empty folders wonโ€™t be detected.


๐ŸŒ Automatic Encoding Detection

treekyt automatically detects and converts multiple character encodings, making it ideal for international Windows systems.

Supported Encodings

  • UTF-8 โ€” Modern systems (Linux, macOS, Windows with UTF-8 console)
  • GBK โ€” Simplified Chinese Windows (GB2312 compatible)
  • SHIFT_JIS โ€” Japanese Windows
  • BIG5 โ€” Traditional Chinese Windows
  • WINDOWS-1252 โ€” Western European Windows

How It Works

When reading input, treekyt:

  1. Tries UTF-8 first โ€” fastest path for modern systems
  2. Falls back to legacy encodings, prioritizing those that:
    • Decode without byte errors and
    • Contain tree structure characters (โ”œ, โ”‚, โ””, โ”€, etc.)
  3. Logs the detected encoding to stderr for transparency

Example: Chinese Windows

# tree /F on Chinese Windows outputs GBK-encoded bytes
tree /F > filetree.txt

# treekyt automatically detects GBK and converts to UTF-8
treekyt -f filetree.txt

Output:

โœ“ Detected encoding: GBK
โœ… Directory structure created successfully!

๐Ÿ“ Example Input & Output

Input (structure.txt):

search_agent/
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ config/
โ”‚   โ””โ”€โ”€ api_keys.yaml
โ””โ”€โ”€ src/
    โ””โ”€โ”€ core/
        โ””โ”€โ”€ agent.py

Result:

  • Directories created: search_agent/, config/, src/, core/
  • Empty files created: README.md, api_keys.yaml, agent.py

โš ๏ธ Important: Files are always empty. No content is restored โ€” only the structure.


โš™๏ธ How Directory Inference Works

treekyt determines if an entry is a directory using two rules:

  1. If the name ends with / or \ โ†’ directory
  2. Otherwise, if a later entry has greater indentation depth โ†’ directory

This allows accurate reconstruction even without trailing slashes (e.g., on Windows).


๐Ÿงช Testing

Run the full test suite:

cargo test

Includes:

  • Unit tests for parser logic
  • Integration tests for filesystem creation
  • Encoding detection tests (GBK, SHIFT_JIS, BIG5)

๐Ÿ”ฎ Future

May support extracting file trees directly from screenshots of terminal output using OCR and tree-layout analysis.


โค๏ธ Inspired By

Commit count: 0

cargo fmt