Giter Site home page Giter Site logo

renameregex's Introduction

renameregex

Renames all files in the current directory using regular expression patterns.

For example renameregex '(.*)\.JPG' '\1\.jpg' will rename all files that end with .JPG to end with .jpg.

Real-world example:

[davidf Letters]$ renameregex '(.*?) *\((.*)\)(.*)' '\2 - \1\3'

Letter to Arlene (2010-08-18).JPG => 2010-08-18 - Letter to Arlene.JPG
Letter to Arlene (2010-08-18).rtf => 2010-08-18 - Letter to Arlene.rtf
Letter to Arlene (2011-03-03).jpg => 2011-03-03 - Letter to Arlene.jpg
Letter to Arlene (2011-11-06).rtf => 2011-11-06 - Letter to Arlene.rtf
Letter to Arlene (2012-02-23).rtf => 2012-02-23 - Letter to Arlene.rtf
Letter to Arlene (2012-07-07).rtf => 2012-07-07 - Letter to Arlene.rtf
Letter to Arlene (2012-11-25).rtf => 2012-11-25 - Letter to Arlene.rtf
Letter-Photo (2011-03-03).graffle => 2011-03-03 - Letter-Photo.graffle

Okay? [y/N] y

It is also possible to specify -r to search subdirectories recursively for files to rename.

Requirements

  • OS X or Linux
  • Python 3.4 or later

Installation

$ mkdir -p ~/bin
$ cd ~/bin
$ git clone https://github.com/davidfstr/renameregex.git
      # ...or download this repository to ~/bin/renameregex
$ echo 'export PATH="$PATH:$HOME/bin/renameregex"' >> ~/.profile

Usage

renameregex filename_regex replacement_pattern

Renames all files in the current directory that match the pattern filename_regex to a new name based on the replacement_pattern.

Before the rename is applied, a preview is printed of what files will be renamed and what they well be renamed to.

Arguments

  • filename_regex โ€” A Perl-compatible regular expression (PCRE), specifically a Python regular expression, that is used to identify files to rename.

  • replacement_pattern โ€” A Python regex replacement string used to generate the new filenames. Expressions like \1 and \2 can be used to refer to groups matched by filename_regex.

Changelog

  • 2.0
    • Features:
      • Add -r option to search directories recursively.
    • Breaking Changes:
      • Substitution patterns use the syntax \1 rather than $1 for backreferences.
    • Internal Changes:
      • Rewrite script in Python rather than Java.
  • 1.0
    • Initial version.

License

This software is licensed under the MIT License.

renameregex's People

Contributors

davidfstr avatar shakeelmohamed avatar

Watchers

 avatar  avatar

renameregex's Issues

Installation issues

  1. Copying the terminal commands is difficult because of the $ in the instructions. If they weren't there I could just copy and paste the entire set of commands into a terminal.
  2. The modification to ~/.profile doesn't seem to work on stock OS X 10.7. Investigation required.
  3. The renameregex trampoline script doesn't work correctly on OS X 10.4.11. The incantation used to determine the current SCRIPT_DIR is incorrectly returning the directory from which renameregex was invoked rather than the directory in which the script resides. Perhaps due to an old version of bash?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.