Might belong in Newbie forum, but question about scripting.
After much googling and utilizing google cached page, I found a batch renaming script for nautilus
here
Code:
#!/bin/bash
#
# multi-file rename script for Nautilus
# (c) Andrey Yurovsky http://andrey.thedotcommune.com/
#
# To install, place this script into your .gnome2/nautilus-scripts/ directory,
# which is located in your home directory. 'rename' should appear in your
# 'scripts' menu when you restart Nautilus (or log out and then log in again).
#
# Select one or more files in Nautilus, right-click one of the selected files,
# and choose 'rename' from the 'scripts' menu. A dialog box will ask for a
# new name. Enter a new name, with a starting index in square brackets
# (ex: [1]). The selected files will be renamed to this new name, incrementing
# the index each time. For example, if the new name is "photo[1].jpg", the
# files will be renamed "photo1.jpg", "photo2.jpg", and so on.
# ask for a name pattern
PATTERN=`zenity --entry --title="Rename Files" --text=name:`
if [ "${#PATTERN}" = "0" ]; then
exit
fi
# check that the pattern looks valid
if [ "`echo $PATTERN | egrep [^\[][\[][0-9]+[\]][^\]]`" != $PATTERN ]; then
zenity --error --text="The name should contain a number in square brackets, for example 'photo[1].jpg' is valid."
exit
fi
# extract the starting index
BNUM="`echo $PATTERN | awk '{printf( "%d-%d", M=match( $1,/[\[]([0-9]+)[\]]/ )+1, RLENGTH+M-3 );}'`"
NUM=`echo $PATTERN | cut -b $BNUM`
# extract the left and right parts of the new name
let L=${BNUM%-*}-2
let R=${BNUM#*-}+2
LEFT=`echo $PATTERN | cut -b 1-$L`
RIGHT=`echo $PATTERN | cut -b $R-`
# rename each file
for FILE in "$@"; do
mv "$FILE" "$LEFT$NUM$RIGHT"
let NUM+=1
done
After I added quotes to the $FILE in:
Code:
for FILE in "$@"; do
mv "$FILE" "$LEFT$NUM$RIGHT"
let NUM+=1
in order to do multiple files with spaces according to
http://g-scripts.sourceforge.net/faq.php .
I wanted to do the following:
A.) Add support for spaces in naming the files-
B.) Start numbering at 01 after filename unless otherwise specified-
C.) Keep existing file extension unless otherwise specified-
Having no knowledge of "egrep" or "awk", and little if any real programming experience, I was wondering if this was possible.
If it is, how would I do it? Don't know how to contact Andrey Yurovsky.
Does anyone have any advice for me besides, "Learn to Code.",?