Skip to main content

Regular expressions bulk rename tool for multiple files

Project description

regex-rename

Regular expressions bulk rename tool for multiple files

GitHub version PyPI version Build Status codecov

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+) ?\).+'
Usage example
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
Usage example

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
Usage example

From now files are named properly:

  • 01 The Invincible.mp3
  • 02 The Invincible.mp3
  • 03 The Invincible.mp3
  • ...
  • 51 The Invincible.mp3

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

regex-rename-0.1.1.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

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

regex_rename-0.1.1-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file regex-rename-0.1.1.tar.gz.

File metadata

  • Download URL: regex-rename-0.1.1.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.3

File hashes

Hashes for regex-rename-0.1.1.tar.gz
Algorithm Hash digest
SHA256 216fb8338664aab62a553294358cbc9beca46803c741fbd49eb326aab2147ac7
MD5 f7e8de53a926e591f2ea3e7c4dd93794
BLAKE2b-256 377901950dd634e8fedfd6ce3a766c2e07ba1e6bc5ec8128bae9b2fb3ba18b59

See more details on using hashes here.

File details

Details for the file regex_rename-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: regex_rename-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.7.3

File hashes

Hashes for regex_rename-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8f60afaab1e102432c2c7678d2aaf0859bcb7eff71029766325ae13b9ba86a65
MD5 9614bcaef86bfcd99460a51962c704a8
BLAKE2b-256 0698f5011a287db59610f70323ae6ebc2bc43addf26bf5830f5011ab38317bbb

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