GithubHelp home page GithubHelp logo

fabiomux / filter_rename Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 144 KB

Bulk file renaming from CLI applying a chain of filters

License: GNU General Public License v3.0

Ruby 99.81% Shell 0.19%
ruby ruby-gem file-renaming file-rename file-renamer mp3-tags

filter_rename's Introduction

FilterRename

FilterRename is a CLI tool created for bulk file renaming that work appending a set of micro operations here called filters, which aim to replace most, if not all, the shell commands usually involved in that kind of operations (sed, awk, trim, ...) in a more safe and comfortable manner.

Ruby Gem Version

Installation

Requirements

These two libraries must be installed:

  • exiv2
  • taglib

With openSUSE:

$ sudo zypper install libexiv2-devel libtag-devel

With Debian/Ubuntu:

$ sudo apt-get install libexiv2-dev libtag1-dev

Rubygem

Install it as a regular Ruby gem with:

$ gem install filter_rename

Usage

To simplify the whole process through a command line, the full filename is logically organized in targets:

<path>/<folder>/<name><ext>

For example, considering the file /home/fabio/Documents/Ruby/filter_rename/Gemfile.lock we have:

  • path: /home/fabio/Documents/Ruby
  • folder: filter_rename
  • name: Gemfile
  • ext: .lock

The chain of filters will be applied to the current target, which is name by default, but can be changed using the --select option on the same command line without running the command twice.

For example, to capitalize the ext and upper case the name at the same time we can use:

filter_rename Gemfile.lock --uppercase --select ext --capitalize

So the file Gemfile.lock becomes GEMFILE.Lock.

To make things easier we can use a special class of filters that target a string as a list of words or numbers with their position used as index.

For example, having the files:

home
  fabio
    Documents
      Photos
        Vacations
          image_from_portofino_0.jpg
          image_from_portofino_1.jpg
          image_from_portofino_2.jpg
          ...

We want:

  • space-separated words in place of the underscore;
  • the first and third word capitalized;
  • the final number must start from 1;
  • the final number must be 2 digits wide.

Using:

$ filter_rename /home/fabio/Documents/Photos/Vacations/*.jpg \
                --spacify '_' \
                --capitalize-word 1:3 \
                --add-number 1,1 \
                --format-number 1,2

The result is:

home
  fabio
    Documents
      Photos
        Vacations
          Image from Portofino 01.jpg
          Image from Portofino 02.jpg
          Image from Portofino 03.jpg
          ...

If you are wondering why all the commands above didn't affected the files physically on the disk, then must be aware of the three main operations contemplated:

  • preview: shows the results verbosly without making any change (default);
  • dry-run: executes a simulation warning also for renaming conflicts;
  • apply: confirm the changes and rename the files unless the destination file exists.

Last but not least filter_rename also supports macros and regular expressions, and the ability to setup configurations params on the fly (config and global).

Get help

Where to start

$ filter_rename --help

More help

More info is available at:

filter_rename's People

Contributors

fabiomux avatar

Watchers

 avatar

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.