Batch Rename Files
Batch rename files using scripts/batch_rename.py. Always run in dry-run mode first to preview changes, then re-run with --execute to apply.
Quick start
python scripts/batch_rename.py <directory> -m <mode> [options]
Modes
| Mode |
Description |
Required Options |
prefix |
Add prefix to filenames |
--prefix <text> |
suffix |
Add suffix before extension |
--suffix <text> |
replace |
Replace text in filenames |
-p <pattern> -r <replacement> |
regex |
Regex substitution |
-p <regex> -r <replacement> |
number |
Sequential numbering |
--start N --padding N |
prefix_number |
Prefix + sequential number |
--prefix <text> --start N --padding N |
Common options
| Option |
Description |
-c, --case |
Case conversion: lower, upper, title, capitalize, snake, kebab, camel, pascal |
--filter <regex> |
Only rename files matching regex |
--ignorecase |
Case-insensitive regex matching |
--recursive |
Include subdirectories |
--noext |
Strip extensions in number modes |
--execute |
Apply changes (skip this flag for dry-run preview) |
Usage patterns
Add prefix/suffix
python scripts/batch_rename.py /path/to/files -m prefix --prefix "img_"
python scripts/batch_rename.py /path/to/files -m suffix --suffix "_backup"
Replace text
python scripts/batch_rename.py /path/to/files -m replace -p "old_text" -r "new_text"
Regex replace
python scripts/batch_rename.py /path/to/files -m regex -p "(d+)" -r "v1"
Sequential numbering
python scripts/batch_rename.py /path/to/files -m number --start 1 --padding 3
python scripts/batch_rename.py /path/to/files -m prefix_number --prefix "photo_" --start 1 --padding 2
Case conversion
python scripts/batch_rename.py /path/to/files -m replace -p "." -r "." -c lower
Filter by pattern
python scripts/batch_rename.py /path/to/files -m prefix --prefix "img_" --filter ".jpg$"
Combine operations
python scripts/batch_rename.py /path/to/files -m replace -p " " -r "_" -c lower
Workflow
- Run in dry-run mode (no
--execute) to preview
- Show the preview to the user for confirmation
- Re-run with
--execute to apply
- Report results
Safety notes
- The script will not overwrite existing files without warning (OS error raised)
- Non-file entries (directories, symlinks) are automatically skipped
- Invalid regex patterns are caught and reported before any file access