Sunday, March 29

Mass Sequential Rename

This program can do the same thing as krename of KDE, for Nautilus in Gnome. It modifies selected files with sequential number.

#!/bin/bash
# Nautilus script for mass file renaming.
# Created by Ben(AT)Fadshop.net. http://benincampus.blogspot.com .Mar 29, 2009
# Based on http://jrfonseca.blogspot.com/2006/05/mass-renaming-in-nautilus.html

set -e

TITLE=`basename "$0"`

EXPR=""

EXPR=`zenity --title "$TITLE - expression" --entry --text "Specify the Prefix for modifying the filenames." --entry-text "$EXPR"` || exit

NUM=0


IFS=$'\n'
for FILE in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS
do
cd "`dirname "$FILE"`"
filename=""`basename "$FILE"`""
EXT="${filename/*./}"

mv ""`basename "$FILE"`"" "$EXPR$NUM.$EXT"
NUM=$((NUM+1))

done


Create a new file ~/.gnome2/nautilus-scripts/Mass Sequential Rename with the content above and change it as executable. Then in Nautilus you can select several files and right click. In the context menu there is a Script->Mass Sequential Rename selection to run the script and rename the files.

4 Comments:

At May 01, 2009 9:36 AM, Anonymous Anonymous said...

FREE TIBET!

 
At June 09, 2009 10:30 AM, Blogger Cristiano Almeida said...

Nice script, it has been very useful to me, but I'm having a problem and would like your help.

Using the script as nautilus script (menu context) it works fine, but I don't know how to use it in terminal. I run "./script filename1 filename2 filename3", enter the prefix, but nothing happens.

 
At June 09, 2009 1:28 PM, Blogger Cristiano Almeida said...

I already realize what happened. ^_^

To run the script as I wanted is needed to replace $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS with $*, and use "./script /path/filename1 /path/filename2 /path/filename3".

 
At June 17, 2009 3:13 PM, Blogger Ben said...

Good job, Cristiano.

 

Links to this post:

Create a Link

<< Home