mass-renamer
A Python script to mass rename files in a directory.
Installation
pip3 install mass_renamer
Usage
Options
Option | Required | Default | Description | Example Usage |
---|---|---|---|---|
-p | X | './' |
The relative folder path to the files you want to rename. | -p "./files-to-rename" |
-q | 🗸 | What to replace within the name of the files or folders to be renamed (query). | -q "Old folder name" |
|
-r | X | '' |
What to replace the names with. | -r "New folder name" |
-t | X | 'file' |
The type of item to replace (dir/file/both). | -t "dir" |
-x | X | Use regex. Whether or not to treat the -q option as a regular expression. |
-x |
|
-v | X | Use verbose logging. | -v |
|
-w | X | 0 | The width for numbers from the ?i and ?j special characters (e.g. passing a value of 4 results in 0001 for index 1 when using the ?j special character). |
-w 4 |
-m | X | Move the files instead of copying them. | -m |
Special Characters
-
-r
- You can use special characters in the replacement text to add special values into file names.-
?i
- This text is replaced with the 0 based index of the file being renamed, which is determined by the order in which the files or folders are being renamed. -
?j
- The same as?i
except it starts at 1. -
?o
- Replaced with the original name of the file. -
?e
- Relaced with the file extension. (e.g.png
).
-
Examples:
-
mass-renamer -p "./" -q ".+" -r "img?i.?e" -t file -w 4 -x
when renaming the first file,maxresdefault.jpg
, results inimg0000.jpg
Example Commands:
-
mass-renamer -p "./files-to-rename" -q "Old folder name" -r "New folder name" -t "dir"
- This command renames all folders in the relative path
./files-to-rename
that contain the nameOld folder name
replaces the character sequenceOld folder name
withNew folder name
. - A folder named
Very Old folder name 2
would be renamed toVery New folder name 2
.
- This command renames all folders in the relative path
-
mass-renamer -p "../other-files-to-rename" -q "(old).*-" -r "newfolder." -t "both" -x
- This command renames all files AND folders in the relative path
../other-files-to-rename
that contain the name matching the regular expression(old).*-
by replacing the character sequence found from the regular expression(old).*-
withnewfolder.
. - A folder named
oldfolder-copy
would be renamed tonewfolder.copy
- This command renames all files AND folders in the relative path
Output
Renamed files are put in a sibling directory of the files / directories being renamed called mass-renamed
.