Skip to main content

Advanced file renaming tool with regex and case transformation support

Project description

renx - Advanced File Renaming Tool

Python Version PyPI version fury.io

renx is a powerful command-line utility for batch renaming files and directories with advanced pattern matching and transformation capabilities.

☕ Support

If you find this project helpful, consider supporting me:

ko-fi

Features ✨

  • Pattern-based renaming 🧩 - Use regex substitutions to transform filenames
  • Case conversion: lower, upper, title, swapcase, capitalize
  • URL-safe names 🌐 - Clean filenames for web use (--urlsafe)
  • Precise file selection 🎯:
    • Include/exclude files with --includes/--excludes
    • Control traversal depth with --max-depth
  • Safe operations 🛡️:
    • Dry-run mode by default (--act to execute) preview changes before executing
    • Bottom-up or top-down processing

📦 Installation

pip install renx

🚀 Usage

python -m renx [OPTIONS] [PATHS...]

Basic Examples

  1. Dry-run preview (default behavior):

    python -m renx /path/to/files
    
  2. Convert filenames to lowercase:

    python -m renx --lower /path/to/files
    
  3. Actually perform renames (disable dry-run):

    python -m renx --act --lower /path/to/files
    
  4. Make filenames URL-safe:

    python -m renx --urlsafe /path/to/files
    

Regex Substitutions Format

The substitution pattern uses this format:

❗search❗replace❗[flags]❗[flags]❗[flags]

Where:

  1. The first character (❗) after -s or --subs acts as the delimiter
  2. The pattern is split into parts by this delimiter

Examples

Simple substitution

-s '/old/new/'
  • Replaces first occurrence of "old" with "new" in each filename

3. Using different delimiters

-s '|old|new|'
  • Uses | as delimiter instead of /

4. Case-insensitive substitution

-s ':old:new:i'
  • Replaces "old", "Old", "OLD", etc. with "new"

5. Complex patterns

-s '/\d+/_/'
  • Replaces one or more digits with an underscore

Supported Flags

The tool supports these regex flags (see Python's re module for complete reference):

Flag Meaning
i Case-insensitive matching
m Multi-line matching
s Dot matches all (including \n)
x Verbose (ignore whitespace)

For example, with -s '/foo/bar/i':

  1. Delimiter = /
  2. Regex = foo
  3. Replacement = bar
  4. Flags = i (case-insensitive)

Special flags:

  • upper, lower, title, swapcase, capitalize - Case transformations
  • ext - Apply to extension only
  • stem - Apply to filename stem only

Examples:

  • -s '/foo/bar/' - Replace 'foo' with 'bar'
  • -s '/\.jpg$/.png/' - Change .jpg extensions to .png
  • -s '/^/prefix_/' - Add prefix to all names
  • -s '/_/-/g' - Replace all underscores with hyphens
  • -s '/.*//upper/' - Convert entire name to uppercase
  • -s '/\..*$//lower/ext' - Convert extension to lowercase

Important Notes

  • The delimiter can be any character (but must not appear unescaped in the pattern)
  • The tool compiles the regex with the specified flags before applying it

Practical Examples

  • Replace spaces with underscores:

    renx -s '/ /_/' /path/to/files
    
  • Remove special characters:

    renx -s '/[^a-zA-Z0-9.]//' /path/to/files
    
  • Add prefix to numbered files:

    renx -s '/(\d+)/image_\1/' *.jpg
    
  • Fix inconsistent extensions (case-insensitive):

    renx -s '/\.jpe?g$/.jpg/i' *
    

Filtering Options

  1. Process only matching files:

    python -m renx --name '*.txt' --lower /path/to/files
    
  2. Exclude directories:

    python -m renx --exclude 'temp/*' /path/to/files
    
  3. Limit recursion depth:

    python -m renx --max-depth 2 /path/to/files
    

Multiple substitution

When your downloaded files look like they were named by a cat walking on a keyboard 😉:

python -m renx \
    -s '#(?:(YTS(?:.?\w+)|YIFY|GloDLS|RARBG|ExTrEmE))##ix' \
    -s '!(1080p|720p|HDRip|x264|x265|BRRip|WEB-DL|BDRip|AAC|DTS)!!i' \
    -s '!\[(|\w+)\]!\1!' \
    -s '/[\._-]+/./' \
    -s '/\.+/ /stem' \
    -s /.+//ext/lower \
    -s '/.+//stem/title' \
    .
# Before: "the.matrix.[1999].1080p.[YTS.AM].BRRip.x264-[GloDLS].ExTrEmE.mKV"
# After: "The Matrix 1999.mkv" 🎬✨

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

renx-0.0.5.tar.gz (28.2 kB view details)

Uploaded Source

Built Distribution

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

renx-0.0.5-py3-none-any.whl (23.5 kB view details)

Uploaded Python 3

File details

Details for the file renx-0.0.5.tar.gz.

File metadata

  • Download URL: renx-0.0.5.tar.gz
  • Upload date:
  • Size: 28.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.17

File hashes

Hashes for renx-0.0.5.tar.gz
Algorithm Hash digest
SHA256 4991a5ebc0f512da48319316289d496777c31c862630e9d419ae99883c8a5bbf
MD5 717f4bcf5b8f1b4753432ad43bf8097b
BLAKE2b-256 3e413fc068229aafa1b6e6bdb27408dd6e6b8e1d33c6333b876a309f872aee19

See more details on using hashes here.

File details

Details for the file renx-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: renx-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 23.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.17

File hashes

Hashes for renx-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 58d542afd2d38443f7ffcc7e1bc9aec8add8be92c1937836e7f2c1ddf6ca256b
MD5 a23f6319689475889c6f37217e1e66ee
BLAKE2b-256 62adcc18003b89d0f7739df065dc399923a495fecd5cbebcb7ebc739a2158f4f

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