Skip to content

JoshuaMichaelHanson/file-folder-copy-replace-1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

File Folder Copy Replace

A powerful, cross-platform Terminal User Interface (TUI) application written in Rust for copying files and folders with advanced content and path replacement capabilities.

🚀 Features

  • Recursive Copy: deeply copies directory structures.
  • Smart Replacements:
    • Path Replacement: Rename directories and files during the copy process.
    • Content Replacement: Find and replace text within files.
  • Filtering:
    • Filter by file extensions (e.g., *.rs, *.txt).
    • Filter by specific filenames.
  • Interactive TUI:
    • Directory Explorer: Navigate your filesystem to select source directories.
    • File Preview: See file contents before copying.
    • Live Configuration: Edit replacement rules and notes on the fly.
  • Save & Load: Persist your configuration templates (config.json) for reusable workflows.
  • Safety: Prevents overwriting existing destination directories to avoid data loss.
  • Performance: Uses multi-threading to keep the UI responsive during large copy operations.

🛠️ How to Build

Ensure you have Rust installed. If not, install it from rustup.rs.

  1. Clone the repository:

    git clone <repository-url>
    cd file-folder-copy-replace
  2. Build the project:

    cargo build --release
  3. Run: The binary will be located in target/release/.

    ./target/release/file-folder-copy-replace

    Or run directly with Cargo:

    cargo run

📖 Usage Guide

Interface Layout

The application is divided into several key areas:

  1. Source Directory: The path you want to copy from.
  2. Source Directory Explorer: A navigable list of folders to help you find your source.
  3. Files in Folder: Shows files in the currently selected explorer folder.
  4. File Preview: Displays the content of the selected file.
  5. Replacement Mapping: Where you define your copy/replace rules.
  6. Generated Destination Directory: The calculated output path based on your rules.
  7. Free Hand Notes: A scratchpad for your own notes (saved with the config).
  8. Buttons: Save, Load, Help, and Copy Replace.

Keybindings

  • Tab / BackTab: Cycle focus between different sections.
  • Enter: Select an item (Explorer) or trigger a button.
  • Arrow Keys: Navigate lists or move cursor in text fields.
  • e: Enter "Editing Mode" for text fields (Source Input, Mapping, Notes).
  • Esc: Exit "Editing Mode" or close popups (Help, Error).
  • q: Quit the application (when in Normal mode).

Configuration Rules (Replacement Mapping)

Define rules in the "Replacement Mapping" text area.

Syntax: Value --ConfigurationType

1. Path & Content Replacement

Format: OldValue=NewValue --Type

  • --path-only: Replaces text in directory and file paths/names only.
  • --files-only: Replaces text inside the file contents only.
  • --path-files: Replaces text in BOTH paths and file contents.

Examples:

production=stage --path-only
v1.0=v2.0 --path-files
TODO=DONE --files-only

2. File Filtering

Format: Value1, Value2, ... --Type

  • --file-types: Only process files with these extensions.
  • --file-names: Only process files with these exact names.

Examples:

*.rs, *.toml, *.md --file-types
config.json, Dockerfile --file-names

📂 Code Structure

For those learning Rust, here is a high-level overview of the codebase:

  • src/main.rs: The entry point. Sets up the terminal (Crossterm), initializes the App state, and runs the main event loop.
  • src/app.rs: Holds the application state (struct App). Handles user input events (on_key, on_mouse) and updates the state accordingly.
  • src/ui.rs: Responsible for rendering the TUI using ratatui. It defines the layout and draws widgets based on the current App state.
  • src/logic.rs: Contains the core business logic:
    • perform_copy_replace: The heavy lifting of walking directories, reading files, replacing text, and writing to the destination.
    • read_directory: Helper to list files for the explorer.
    • Config & Template: Structs for parsing rules and saving/loading JSON.

🎓 Learning Rust?

Check the source code! We've added detailed comments explaining various Rust concepts used in this project, such as:

  • Structs & Enums
  • Result & Option handling
  • Multi-threading with Channels (mpsc)
  • File I/O & Iterators
  • Closures
  • Serde (Serialization/Deserialization)

About

A powerful, cross-platform Terminal User Interface (TUI) application written in Rust for copying files and folders with advanced content and path replacement capabilities.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages