Skip to main content

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.
  • Gitignore Compliance: Option to respect .gitignore rules, excluding files and directories as specified.
  • Custom Ignore Files: Support for additional ignore files to further customize exclusions.
  • Automatic Encoding Detection: Uses chardet to 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

  1. Clone the Repository:

    git clone https://github.com/yourusername/r2t.git
    cd r2t
    
  2. Create a Virtual Environment (Recommended):

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
    
  3. 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) Choose yes or no to respect .gitignore rules. Default is no.
  • --ignore-file: (Optional) Path to an additional ignore file.
  • --files: (Optional) Comma-separated list of specific files to include.

Examples

  1. Combine All Python Files in the Current Directory:

    python r2t.py --path . --ext .py --out combined_python.txt
    
  2. 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
    
  3. Combine All .txt and .md Files, Respecting .gitignore:

    python r2t.py --path . --ext .txt,.md --out combined_text.md --respect-git yes
    
  4. 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:

  1. Directory Tree: A visual representation of the included directories and files.
  2. Combined File Contents: The content of each included file, clearly separated and labeled with its path.
  3. 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:

  1. Fork the Repository
  2. Create a Feature Branch: git checkout -b feature/YourFeature
  3. Commit Your Changes: git commit -m 'Add some feature'
  4. Push to the Branch: git push origin feature/YourFeature
  5. 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.

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

r2t-0.1.5.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

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

r2t-0.1.5-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file r2t-0.1.5.tar.gz.

File metadata

  • Download URL: r2t-0.1.5.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.11

File hashes

Hashes for r2t-0.1.5.tar.gz
Algorithm Hash digest
SHA256 ecb0683bca6d7c34e838c73eabc899992e837bf51a253fd69c92a3471fcbbf09
MD5 7e3502da9ad6f0bfafc416f4aec5592a
BLAKE2b-256 03b5c032b9925c16f9082b894edf75715298ac9b5c5ab11145d5cc82dc1a3e4f

See more details on using hashes here.

File details

Details for the file r2t-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: r2t-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.11

File hashes

Hashes for r2t-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 dacdb9d3278a9979b7b6882b9227b6d3f5407e9cfaefd235bbd36451985380c6
MD5 01c41e6748daf6de15f79b3f74c55c63
BLAKE2b-256 e7b5b5ba83170a9bfcd96c9d5424bfa6d1e59da31b574dcd9431395f3e793353

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