A memory-efficient directory to XML converter written in Go. This tool recursively processes directories and converts text files into a structured XML format, with smart file filtering and automatic exclusion of problematic directories.
- Memory Efficient: Uses buffered reading and reasonable memory limits
- Smart Filtering: Automatically excludes problematic directories (node_modules, .git, etc.)
- File Type Support: Processes common text files while skipping binary files
- Progress Tracking: Real-time progress updates with detailed statistics
- Error Handling: Graceful error handling with clear reporting
- Compression Support: Optional gzip compression for output files
- Download the latest release for your platform from the releases page
- Extract the archive:
# For Linux/macOS: tar -xzf xdir-<os>-<arch>.tar.gz # For Windows: unzip xdir-windows-<arch>.zip
- Install the binary:
# Linux/macOS: sudo ./install.sh # Windows: # Move xdir.exe to a directory in your PATH
-
Clone the repository:
git clone https://github.com/yourusername/xdir-context.git cd xdir-context
-
Build the binary:
go build -o xdir
-
Install to system (optional):
sudo mv xdir /usr/local/bin/
xdir [flags] sourcedir [output.xml]
If no output file is specified, it defaults to output.xml
.
-
-patterns
: File extensions to include (comma-separated)xdir -patterns=js,ts,md sourcedir output.xml
-
-glob
: Glob patterns to match files (comma-separated)xdir -glob="*.min.js,*.config.js" sourcedir output.xml
-
-compress
: Enable gzip compression for outputxdir -compress sourcedir output.xml.gz
-
-max-size
: Maximum file size in bytes (default: 10MB)xdir -max-size=5242880 sourcedir output.xml
-
-unsafe
: Allow processing of normally excluded pathsxdir -unsafe sourcedir output.xml
The tool generates XML in the following format:
<?xml version="1.0" encoding="UTF-8"?>
<files>
<file name="path/to/file.js" size="1234">
<![CDATA[
// File contents here
]]>
</file>
<!-- Additional files -->
</files>
By default, the following paths are excluded:
- node_modules
- .git
- .env files
- .DS_Store
- Hidden files/directories (starting with .)
Use the -unsafe
flag to process these paths.
The tool supports these file types by default:
- Web:
.html
,.css
,.js
,.jsx
,.ts
,.tsx
,.json
- Documents:
.txt
,.md
,.mdx
,.xml
,.yaml
,.yml
- Programming:
.go
,.py
,.java
,.c
,.cpp
,.h
,.hpp
,.rs
,.rb
,.php
- Memory usage remains constant regardless of directory size
- Files larger than max-size are skipped (default 10MB)
- Binary files (images, videos, etc.) are automatically skipped
- Efficient buffered reading for large files
- Progress reporting for long-running operations
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.