Regular expressions bulk rename tool for multiple files
Project description
regex-rename
Regular expressions bulk rename tool for multiple files
Usage
enter regex-rename
for help:
$ regex-rename
regex-rename v0.1.1 (nuclear v1.1.5) - Regular expressions bulk rename tool for multiple files
Usage:
regex-rename [OPTIONS] PATTERN [REPLACEMENT]
Arguments:
PATTERN - Regex pattern to match filenames
[REPLACEMENT] - Replacement regex pattern for renamed files. Use \1, \2 syntax to make use of matched groups
Options:
--version - Print version information and exit
-h, --help [SUBCOMMANDS...] - Display this help and exit
-r, --rename - Does actual renaming files instead of just testing replacement pattern
--full - Enforces matching full filename against pattern
--pad-to PAD_TO - Applies padding with zeros with given length on matched numerical groups
Installation
pip3 install regex-rename
Requirements:
- Python 3.6 (or newer) with pip
Example
Imagine you've got audio files awfully named like this:
Stanis▯aw+Lem+Invincible+(1).mp3
Stanis▯aw+Lem+Invincible+(2 ).mp3
Stanisław_Lem_Invincible (3) .mp3
- ...
Stanis▯aw+Lem+Invincible+(51).mp3
and you want to rename all of them in a manner 01 The Invincible.mp3
(extracting number from the end and put it at the beginning and padding it to 2 digits by the way).
Step 1: Testing matching pattern
Our Regex pattern to match those files and extract number from parentheses should be like this: .+\((\d+) ?\).+
Let's test matching pattern: regex-rename '.+\((\d+) ?\).+'
Notice that regex groups are extracted in logs.
Step 2: Testing replacement pattern
We'd like to replace all files to a pattern: \1 The Invincible.mp3
(\1
is a first extracted group from matching pattern).
Regex can't easily pad numbers with zeros. Fortunately, we can use --pad-to=2
to obtain 2-digit numbers
Let's test it: regex-rename '.+\((\d+) ?\).+' '\1 The Invincible.mp3' --pad-to=2
Step 3: Actual renaming
All above commands were just testing our patterns so that we could experiment with regex patterns. Only when we're sure that everything is matched correctly, we can use --rename
flag which does the actual renaming:
regex-rename '.+\((\d+) ?\).+' '\1 The Invincible.mp3' --pad-to=2 --rename
From now files are named properly:
01 The Invincible.mp3
02 The Invincible.mp3
03 The Invincible.mp3
- ...
51 The Invincible.mp3
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for regex_rename-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f60afaab1e102432c2c7678d2aaf0859bcb7eff71029766325ae13b9ba86a65 |
|
MD5 | 9614bcaef86bfcd99460a51962c704a8 |
|
BLAKE2b-256 | 0698f5011a287db59610f70323ae6ebc2bc43addf26bf5830f5011ab38317bbb |