Thursday, August 12, 2010

Mass rename files in Midnight Commander

Here is another script for Midnight Commander to allow for mass renaming of flagged files. To use it you will need to add it to your MC menu file in /etc/mc/mc.menu or ~/.mc/menu.

+ t t
e       Rename tagged files
        set %t; CMD=%{Enter regex}
        while [ -n "$1" ]; do
          echo rename -\"s"$CMD"e\" "$1"
          rename -\"s"$CMD"e\" "$1"
          shift
        done

first you will need to flag the files toy want to rename then execute the user operation. When you do so you will be prompted for the regular expression you with to execute.

Some examples:
 /oldword/newword/   # Change a word.
 /_/ /g   # Replace all _'s with spaces.
 /_\[.*\]//   # Remove _[CRCHASH] tags.
 /\(.*\)//   # Remove (...) sections.

1 comment:

Reis said...

ok. This is a relevant post. I think anyone who uses mc may arrive at this point some day. But I don't understand about shell regex. Couldn't understand how should I activate the script, I mean, which is the keyboard shortcut to activate it? Furthermore, what if I want to erase some part of all files, for example:

2020Fev17_0.xml -> 0.xml ?

Anyway, thanks for the script. I'm gonna bookmark it, I'm sure I'm going to use it someday