A tool to combine multiple files from a directory and its subdirectories into a single output file
Project description
r2t (Recursive File Combiner)
Overview
r2t (Recursive to Text) is a powerful Python tool designed to combine multiple files from a directory and its subdirectories into a single output file. It offers flexibility in file selection, respects .gitignore rules, and provides a clear visualization of the included files. Whether you're consolidating code for review, preparing documentation, or creating backups, r2t streamlines the process with its robust features and user-friendly interface.
Features
- Recursive File Scanning: Searches through all subdirectories from a given path.
- Flexible File Selection:
- Combine files based on extensions (e.g.,
.py,.md,.txt). - Specify individual files from different subdirectories.
- Combine files based on extensions (e.g.,
- Gitignore Compliance: Option to respect
.gitignorerules, excluding files and directories as specified. - Custom Ignore Files: Support for additional ignore files to further customize exclusions.
- Automatic Encoding Detection: Uses
chardetto automatically detect and handle various file encodings. - Comprehensive Error Handling: Gracefully manages permission issues, missing files, and encoding errors.
- Directory Tree Visualization: Generates a clear tree structure of included files and directories in the output.
- Detailed Output:
- Combines file contents with clear separators and file path information.
- Lists any specified files that were not found.
Installation
-
Clone the Repository:
git clone https://github.com/yourusername/r2t.git cd r2t
-
Create a Virtual Environment (Recommended):
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install Dependencies:
pip install -r requirements.txt
Usage
Run the r2t.py script with the desired arguments to combine files.
Command-Line Arguments
--path: (Required) Target directory path to scan for files.--ext: (Optional) Comma-separated list of file extensions to include (e.g.,.py,.md,.txt).--out: (Required) Output filename where the combined content will be saved.--respect-git: (Optional) Chooseyesornoto respect.gitignorerules. Default isno.--ignore-file: (Optional) Path to an additional ignore file.--files: (Optional) Comma-separated list of specific files to include.
Examples
-
Combine All Python Files in the Current Directory:
python r2t.py --path . --ext .py --out combined_python.txt
-
Combine Specific Files from Different Subdirectories:
python r2t.py --path . --files src/main.py,docs/README.md,tests/test_main.py --out important_files.txt
-
Combine All
.txtand.mdFiles, Respecting.gitignore:python r2t.py --path . --ext .txt,.md --out combined_text.md --respect-git yes
-
Use an Additional Ignore File:
python r2t.py --path . --ext .py --out combined_python.txt --ignore-file custom_ignore.txt
Output Structure
The output file contains:
- Directory Tree: A visual representation of the included directories and files.
- Combined File Contents: The content of each included file, clearly separated and labeled with its path.
- Summary of Missing Files: If specific files were requested but not found, they are listed at the end.
Error Handling
r2t handles various scenarios gracefully:
- Permission Denied: Skips files or directories without necessary permissions and logs a warning.
- File Not Found: Notifies if a specified file does not exist.
- Encoding Errors: Reports if a file's encoding cannot be detected or read.
- Invalid Directory: Checks if the specified path is a valid directory.
Contributing
Contributions are welcome! Please follow these steps:
- Fork the Repository
- Create a Feature Branch:
git checkout -b feature/YourFeature - Commit Your Changes:
git commit -m 'Add some feature' - Push to the Branch:
git push origin feature/YourFeature - Open a Pull Request
License
This project is licensed under the MIT License.
Acknowledgements
- Uses the chardet library for robust encoding detection.
- Inspired by the need for efficient file consolidation in software development and documentation processes.
GUI Usage
r2t now includes a graphical user interface for easier use. To launch the GUI:
-
Install r2t and its GUI dependencies using pip:
pip install r2t[gui] -
Run the GUI:
r2t-gui
Note: The GUI requires Tkinter, which is usually included with Python installations. If you encounter any issues, make sure Tkinter is properly installed on your system.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file r2t-0.1.7.tar.gz.
File metadata
- Download URL: r2t-0.1.7.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d2cf35906029202e8da618a94ddb2276c6359477ff65821f56b8a7a89dfdba8b
|
|
| MD5 |
0be8b5850ba9016eebb33f44f2608b49
|
|
| BLAKE2b-256 |
166cb7f7c8997c9fe14fd7ee5ddf81c4340efd0196afcce33a293d4b94ead9d8
|
File details
Details for the file r2t-0.1.7-py3-none-any.whl.
File metadata
- Download URL: r2t-0.1.7-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1bcf8f21204e93b6ab7588406f8a6f13f9a2d9357f86ee392fa1bf4489d63ea6
|
|
| MD5 |
7757af26b46b92834110fbc23777a297
|
|
| BLAKE2b-256 |
bb1a9c64cf2eb3f61fa8105dcccb65ab146d7d417efce05a9be48e1c88ec1a1d
|