Skip to main content

A powerful, zero-dependency cross-platform CLI file renaming utility

Project description

๐Ÿ—‚๏ธ rnmtool - File Rename Utility

A powerful, zero-dependency, cross-platform CLI for batch renaming files - with a safe dry-run preview.

PyPI version Python License CI Stars

pipx install rnmtool

Works on Windows, macOS, and Linux - invoke from any folder, any terminal.


โœจ Why rnmtool?

Feature rnmtool Manual renaming PowerShell scripts
Safe dry-run preview โœ… โŒ โŒ
Regex support โœ… โŒ โš ๏ธ complex
Zero dependencies โœ… - โœ…
Works on Win / Mac / Linux โœ… โŒ โŒ
One-word invocation โœ… โŒ โŒ
Glob file filtering โœ… โŒ โš ๏ธ complex
Recursive directory support โœ… โŒ โš ๏ธ complex

๐Ÿ“‹ Table of Contents


Installation

Recommended: pipx (cross-platform, isolated)

pipx install rnmtool

Don't have pipx? Install it first: pip install pipx

Alternative: pip

pip install rnmtool

One-command installer scripts

Windows (PowerShell):

irm https://raw.githubusercontent.com/AayushGoswami/rnmtool/main/scripts/install.ps1 | iex

Linux / macOS (Bash):

curl -fsSL https://raw.githubusercontent.com/AayushGoswami/rnmtool/main/scripts/install.sh | bash

Verify installation

rnmtool --help

Quick Start

# Always preview first - no files are changed
rnmtool test_files --dry-run --find " " --replace "_"

# If the preview looks good, apply (remove --dry-run)
rnmtool test_files --find " " --replace "_"

# Run from inside the target folder (no directory argument needed)
cd /path/to/my/folder
rnmtool --dry-run --case lower

All Options

usage: rnmtool [-h] [--pattern GLOB] [--recursive] [--dry-run] [--overwrite]
               [--find TEXT] [--replace TEXT] [--regex] [--prefix TEXT]
               [--suffix TEXT] [--ext EXT] [--case {lower,upper,title}]
               [directory]

Positional Arguments

Argument Description Default
directory The folder containing files to rename . (current folder)

General Options

Flag Short Description
--pattern GLOB -p Only rename files matching this glob (e.g. "*.txt")
--recursive -r Search subdirectories recursively
--dry-run -n Preview changes without modifying any file
--overwrite Allow overwriting a file if the new name already exists
--help -h Show help message and exit

Transformation Options

Flag Short Description
--find TEXT -f Text (or regex pattern) to search for in filenames
--replace TEXT -s Replacement text (default: empty - deletes the match)
--regex -x Treat --find as a regular expression
--prefix TEXT Text to prepend to every filename
--suffix TEXT Text to append to every filename (before the extension)
--ext EXT Replace the file extension (e.g. .jpg or jpg)
--case -c Convert case: lower, upper, or title

Transformation order: find/replace โ†’ case โ†’ prefix/suffix โ†’ extension


Tutorials

All examples below use the included test_files/ folder. Always run with --dry-run first to preview changes safely.


1. Dry-Run Preview

Preview what would happen without touching any file. A โœ“ mark appears next to filenames that would be changed.

rnmtool test_files --dry-run --case lower

Preview output:

  BEFORE                        AFTER
  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
  04 helper SCRIPT.py           04 helper script.py   โœ“
  07 settings.XML               07 settings.xml       โœ“
  12 USER preferences.ini       12 user preferences.ini โœ“

No files are modified. Remove --dry-run to apply changes.


2. Add a Prefix

Prepend a label or date to every filename in a folder.

# Dry-run first
rnmtool test_files --dry-run --prefix "2025_"

# Apply
rnmtool test_files --prefix "2025_"

Result:

01 My Notes.txt          โ†’  2025_01 My Notes.txt
02 Sales Data 2024.csv   โ†’  2025_02 Sales Data 2024.csv
03 AppConfig.json        โ†’  2025_03 AppConfig.json

Tip: Combine with --pattern to prefix only specific file types:

rnmtool test_files --pattern "*.csv" --prefix "report_"

3. Add a Suffix

Append a label to every filename (inserted before the extension).

# Dry-run first
rnmtool test_files --dry-run --suffix "_backup"

# Apply
rnmtool test_files --suffix "_backup"

Result:

01 My Notes.txt        โ†’  01 My Notes_backup.txt
05 README draft.md     โ†’  05 README draft_backup.md
11 RunBackup.bat       โ†’  11 RunBackup_backup.bat

4. Find & Replace Text

Replace any text string inside filenames - spaces, words, anything.

Example A - Replace spaces with underscores

rnmtool test_files --dry-run --find " " --replace "_"
rnmtool test_files --find " " --replace "_"

Result:

01 My Notes.txt          โ†’  01_My_Notes.txt
02 Sales Data 2024.csv   โ†’  02_Sales_Data_2024.csv
08 app ERROR log.log     โ†’  08_app_ERROR_log.log

Example B - Remove a specific word

rnmtool test_files --find " draft" --replace ""

Result:

05 README draft.md   โ†’  05 README.md

Example C - Replace a word with another

rnmtool test_files --find "ERROR" --replace "error"

Result:

08 app ERROR log.log   โ†’  08 app error log.log

5. Regex Find & Replace

Use regular expressions for advanced pattern-based renaming. Enable with the --regex (or -x) flag alongside --find.

Example A - Strip leading numbers from filenames

rnmtool test_files --dry-run --regex --find "^\d+\s"
rnmtool test_files --regex --find "^\d+\s"

Result:

01 My Notes.txt        โ†’  My Notes.txt
02 Sales Data 2024.csv โ†’  Sales Data 2024.csv
03 AppConfig.json      โ†’  AppConfig.json

Example B - Remove all digits from filenames

rnmtool test_files --regex --find "\d+" --replace ""

Example C - Replace multiple spaces with a single underscore

rnmtool test_files --regex --find "\s+" --replace "_"

6. Convert Case

# Lowercase
rnmtool test_files --case lower

# Uppercase
rnmtool test_files --case upper

# Title Case
rnmtool test_files --case title

Title case result:

08 app ERROR log.log   โ†’  08 App Error Log.log
10 CREATE tables.sql   โ†’  10 Create Tables.sql

7. Change File Extension

Normalize .XML to .xml

rnmtool test_files --pattern "*.XML" --ext .xml

Convert .yaml to .yml

rnmtool test_files --pattern "*.yaml" --ext .yml

Change .txt to .md

rnmtool test_files --pattern "*.txt" --ext .md

The leading dot is optional: --ext yml and --ext .yml both work.


8. Filter by Glob Pattern

# Only .log files
rnmtool test_files --pattern "*.log" --prefix "archived_"

# Files starting with "0"
rnmtool test_files --pattern "0*" --case lower

# Only .json files
rnmtool test_files --pattern "*.json" --suffix "_v2"

9. Recursive Renaming

# Rename all .txt files in test_files and any subfolders
rnmtool test_files --recursive --pattern "*.txt" --case lower

# Always dry-run first with recursive!
rnmtool test_files --recursive --dry-run --find " " --replace "_"

10. Combine Multiple Transformations

Transformations are applied in order: find/replace โ†’ case โ†’ prefix/suffix โ†’ extension

Clean up all filenames at once

rnmtool test_files --find " " --replace "_" --case lower --prefix "2025_"

Result:

01 My Notes.txt         โ†’  2025_01_my_notes.txt
08 app ERROR log.log    โ†’  2025_08_app_error_log.log
12 USER preferences.ini โ†’  2025_12_user_preferences.ini

Strip numbers, title-case, add suffix

rnmtool test_files --regex --find "^\d+\s" --case title --suffix "_final"

Pattern-scoped multi-transform

rnmtool test_files --pattern "*.py" --case lower --prefix "script_"

Test Files

A test_files/ folder is included with 12 dummy files of varied types to safely experiment:

File Extension
01 My Notes.txt .txt
02 Sales Data 2024.csv .csv
03 AppConfig.json .json
04 helper SCRIPT.py .py
05 README draft.md .md
06 index PAGE.html .html
07 settings.XML .XML
08 app ERROR log.log .log
09 docker-compose.yaml .yaml
10 CREATE tables.sql .sql
11 RunBackup.bat .bat
12 USER preferences.ini .ini

Contributing

Contributions are welcome! Please read CONTRIBUTING.md for guidelines.


Safety Notes

  • โœ… Always use --dry-run before applying any changes.
  • โœ… Files whose names are unchanged by a transformation are automatically skipped.
  • โš ๏ธ If a rename would cause a name collision, the tool skips that file and warns you. Use --overwrite only if you are sure.
  • โš ๏ธ Recursive mode (--recursive) can affect many files. Always dry-run first.
  • โ„น๏ธ The tool only renames files - it never moves, deletes, or modifies file contents.

Built with Python's standard library - zero dependencies. Works on Windows, macOS, and Linux.

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

rnmtool-1.0.1.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

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

rnmtool-1.0.1-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file rnmtool-1.0.1.tar.gz.

File metadata

  • Download URL: rnmtool-1.0.1.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for rnmtool-1.0.1.tar.gz
Algorithm Hash digest
SHA256 9051ec9d71a6a900da844414d7f1795e45cd31f5734ca59c48749961df76cc83
MD5 58474d02a94ea000a770258bb89ed579
BLAKE2b-256 9476bbe4961f0a0c80d687cddea982984ea22c42758e8374ba8fb66473b7bf15

See more details on using hashes here.

File details

Details for the file rnmtool-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: rnmtool-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for rnmtool-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9a56fc5934a65a1c741e29fc155587f9ecbbec56636a6416c0c6b248f3d87298
MD5 cd22e4837e420d568163d66adb5920c3
BLAKE2b-256 5c986f6343367488d9d4426753275215e4a840759101f1eec4eb7c9a0b4a1da4

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