Skip to main content

No project description provided

Project description

py-rename

Python bulk rename package

Usage

enter py-rename -h for help

$ py-rename -h

py-rename v0.1.0 - 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's version number and exit
  -s, --silent          do not print output (default: False)
  -n, --dryrun          Dry run: print names of files to be renamed, but don't
                        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).txt
  • ab12+Red+(0001).txt
  • ab12+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.txt
  • 01-Red.txt
  • 02-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',)

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

py-rename-0.1.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

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

py_rename-0.1.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file py-rename-0.1.0.tar.gz.

File metadata

  • Download URL: py-rename-0.1.0.tar.gz
  • Upload date:
  • Size: 6.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/50.0.0.post20200830 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for py-rename-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f9a4e61b9fbe5a1d4df870f3df4c68ddb99a9875e5ff33766474f6825f0b6e32
MD5 1be6698347af5a7aea044d205b824b37
BLAKE2b-256 25e0e6db5b7a4982850703c84d39a88db09d04f7f4826412313e09589bd895d5

See more details on using hashes here.

File details

Details for the file py_rename-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: py_rename-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 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/50.0.0.post20200830 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for py_rename-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9ad49d4cee828847959a1e08c3b667d6555fa6ba6e966f8d6cafef36313b8f01
MD5 cbdfa1e05dee169db0604dceea11559b
BLAKE2b-256 2b4ac956c5aa66892321855cd83f202e869261884bd276cc8739a879069ef50a

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