py-rename
Python bulk rename package
Usage
enter py-rename -h for help
$ py-rename -h
py-rename - Python rename tool for multiple files
Usage:
py-rename [OPTIONS] COMMAND [COMMAND-OPTIONS]
Positional arguments:
rename rename files based on regex pattern
match rename files based on regex pattern
prefix prefix filenames with prefix string
postfix postfix filenames with prefix string
lower convert filenames to lowercase
replace replace spaces in filenames to _
camelcase convert filenames to camel case
Options:
-h, --help show this help message and exit
-V, --version show program version number and exit
-s, --silent do not print output (default: False)
-n, --dryrun Dry run: print names of files to be renamed, but do not
rename (default: False)
-f, --full Match only full filename against pattern (default:
False)
Subcommand usage example:
$ py-rename rename -h
Positional arguments:
pattern regex pattern to match filenames
replacement replacement regex pattern for renamed files
Options:
-h, --help show this help message and exit
Installation
pip3 install py-rename
Requirements:
- Python 3.6 (or higher)
Examples
Example 1 - Renaming based on regex
Imagine you have some files awfully named like this:
ab12+Red+(0000).txtab12+Red+(0001).txtab12+Red+(0002).txt
and you want to rename all of them in manner 01-Red.txt (extracting number from the end and put it at the beginning and shortening it to 2 digits).
Step 1: Test matching pattern
Regex pattern to match those files and extract 2 digit number should be like this: .+\(00(\d{2})\).+
$ py-rename match ".+\(00(\d{2})\).+"
('matched ab12+Red+(0000).txt',)
('matched ab12+Red+(0001).txt',)
('matched ab12+Red+(0002).txt',)
('files matched: 3',)
Step 2: Test replacement pattern using dryrun flag
$ py-rename -n rename ".+\(00(\d{2})\).+" "\1-Red.txt"
Performing DryRun: No actions will be taken
('renaming: ab12+Red+(0000).txt --> 00-Red.txt',)
('renaming: ab12+Red+(0001).txt --> 01-Red.txt',)
('renaming: ab12+Red+(0002).txt --> 02-Red.txt',)
('files matched: 3',)
Step 3: Actual renaming
$ py-rename rename ".+\(00(\d{2})\).+" "\1-Red.txt"
('renaming: ab12+Red+(0000).txt --> 00-Red.txt',)
('renaming: ab12+Red+(0001).txt --> 01-Red.txt',)
('renaming: ab12+Red+(0002).txt --> 02-Red.txt',)
('files matched: 3',)
Example 2 - Add prefix string or postfix string to files
Imagine you have some files named like this:
00-Red.txt01-Red.txt02-Red.txt
Add prefix string:
$ py-rename prefix "test_"
('renaming: 00-Red.txt --> test_00-Red.txt',)
('renaming: 01-Red.txt --> test_01-Red.txt',)
('renaming: 02-Red.txt --> test_02-Red.txt',)
('files matched: 3',)
Add postfix string:
$ py-rename postfix "_test"
('renaming: 00-Red.txt --> 00-Red_test.txt',)
('renaming: 01-Red.txt --> 01-Red_test.txt',)
('renaming: 02-Red.txt --> 02-Red_test.txt',)
('files matched: 3',)
Metadata
Release files for py-rename 1.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| py-rename-1.4.0.tar.gz | 7.2 kB | Without provenance | Details for py-rename-1.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| py_rename-1.4.0-py3-none-any.whl | Python 3 | none | any | Details for py_rename-1.4.0-py3-none-any.whl |
Total release size: 17.4 kB
Release files / py-rename-1.4.0.tar.gz
| Download URL | py-rename-1.4.0.tar.gz |
|---|---|
| Size | 7.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
701a09e1e50cfa7557320b2ff71994fd9a39b592f43b688034efa83e2ad608e1
|
|
BLAKE2b-256 checksum How to use checksums |
1818811859cd815ca31bdfc6d80c44445e1992a818bf169f1e48a3855e5e1b00
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
|
Release files / py_rename-1.4.0-py3-none-any.whl
| Download URL | py_rename-1.4.0-py3-none-any.whl |
|---|---|
| Size | 10.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d01a6efcd21de82987a819c0babea3a7b51c3a99264823f4e0aaa595ae90ca62
|
|
BLAKE2b-256 checksum How to use checksums |
dbde6f2822aa3b1acbc62e4d9235da2c227916798e5caaaa9d893b2becb82de8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
|
Security for py-rename 1.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.