A CLI application that takes a regex patten for search and replace and then recursively renames files according to the regex pattern. https://git.kemitix.net/kemitix/rename-files
Find a file
ForgeJo Action. See: https://git.kemitix.net/kemitix/rust c81b243911
All checks were successful
Test / build (map[name:nightly]) (pull_request) Successful in 33s
Test / build (map[name:stable]) (pull_request) Successful in 32s
chore: release v0.1.0
Signed-off-by: ForgeJo Action. See: https://git.kemitix.net/kemitix/rust <action@git.kemitix.net>
2025-01-14 20:39:16 +00:00
.forgejo/workflows build: add forgejo workflows 2025-01-14 20:37:28 +00:00
src build: add forgejo workflows 2025-01-14 20:37:28 +00:00
.gitignore Initial commit 2024-12-30 14:34:29 +00:00
Cargo.lock Initial commit 2024-12-30 14:34:29 +00:00
Cargo.toml Initial commit 2024-12-30 14:34:29 +00:00
CHANGELOG.md chore: release v0.1.0 2025-01-14 20:39:16 +00:00
README.md Initial commit 2024-12-30 14:34:29 +00:00

rename-files

A CLI application that takes a regex patten for search and replace and then recursively renames files according to the regex pattern.

Uses clap to define and parse command-line arguments:

  • -s or --search: The regex pattern to search for
  • -r or --replace: The replacement pattern
  • -d or --directory: The starting directory (optional, defaults to current directory)
  • --dry-run: Option to preview changes without actually renaming files

Recursively walks through the directory structure using walkdir.

Applies the regex pattern to each file name and performs the replacement if there's a match.

Provides a dry-run option to preview changes before making them.

# Replace "old" with "new" in all file names
cargo run -- --search "old" --replace "new"

# Replace numbers with "X" in all file names, starting from a specific directory
cargo run -- --search "[0-9]" --replace "X" --directory "/path/to/dir"

# Preview changes without actually renaming (dry run)
cargo run -- --search "test_" --replace "" --dry-run

The program will:

  • Only rename files (not directories)
  • Show you what changes it's making
  • Handle errors gracefully
  • Allow you to preview changes with --dry-run before making actual changes

Safety features:

  • Checks if the new filename would be different before attempting to rename
  • Uses proper error handling throughout
  • Provides feedback about what's being renamed
  • Allows preview of changes before making them

Remember that regex patterns are powerful and should be used carefully, especially when batch renaming files. It's recommended to always use the --dry-run option first to preview the changes before actually renaming files.