[Leaplist] help with renaming script
Dan Cherry
dan.s.cherry at gmail.com
Thu Dec 24 19:43:41 EST 2009
Ray Brunkow wrote:
> I do not know how to script. I have a simple script that I got some
> help about a year back or so to replace spaces with _ but now i am in
> need of replacing entire file names with sequential numbers in order to
> get them to function properly with Dreamweaver to make a photo album of
> roughly 200M worth of pictures. I really do not want to go and manually
> rename every single file. that would just take way to long.
>
> ====================
>
> #!/bin/bash
> #
> # remove spaces in names of files and replace them with '_'
> #
> function basic {
> for i in *
> do
> if [ -d "$i" ]
> then
> cd "$i"
> remove_space2.sh #name of this script from LQ
> member dive. Must be in PATH or full path to script must be given.
> cd ..
> fi
> tempa=$(echo "$i" | sed 's/ /_/g' | sed 's/_-_/-/g' |
> sed -e 's/\ -\ /-/g' | sed 's/__/_/g' \
> | sed "s#'##g" | sed "s#;##g" | sed "s#,##g")
> [[ "$i" != "$tempa" ]] && mv -v "$i" "$tempa"
> done
> }
>
> function cmd {
> for i in "$@"
> do
> tempa=$(echo "$i" | sed 's/ /_/g' | sed 's/_-_/-/g' |
> sed -e 's/\ -\ /-/g' | sed 's/__/_/g' \
> | sed "s#'##g" | sed "s#;##g" | sed "s#,##g")
> [[ "$i" != "$tempa" ]] && mv -v "$i" "$tempa"
> [[ ! -d "$tempa" ]] && break
> cd "$tempa"
> remove_space2.sh #name of this script from LQ member
> dive. Must be in PATH or full path to script must be given.
> cd ..
> done
> }
>
> [[ "$@" != "" ]] && cmd "$@"
> [[ "$@" == "" ]] && basic
>
> ==============
>
> is there a simple way to modify that script to do what i need? no i did
> not code that. the good folks over at LinuxQuestions.org helped with
> that one.
>
You might want to take a look at krename or gnome-commander. Both have
extremely flexible 'advanced' rename capabilities, selected with
pulldowns and variable names. They also let you see the resulting file
names BEFORE you commit the change, saving aggravation if you make a
typo on the command line. Gnome-commander will let you rename files
with sequence numbers, as well as replace spaces or whatever with
anything you want.
IMHO, scripts are best if you use them often enough to stay fresh on the
syntax. But if you're like me, and only use them a couple times a year,
then cheater apps aren't a bad way to go.
I know that's not what you asked, but it's a quick way to achieve what
you're doing.
BTW, I just found something super-slick in gnome-commander. Like you, I
had a ton of photos to rename, but I also had to merge them with photos
my wife took on the same trip. gnome-commander allows you to extract
exif info from the jpg file to use in the new filename, so we're able to
change the file name to the date-time stamp on the photo with some other
data, and both sets of photos sort into the sequence they were taken ;-)
It's not consecutive, but definitely sequential.
While I was typing, I saw that Bryan gave you the answer you were
looking for, but you may still want to look at gnome-commander to see
how it can access the metadata if it's relevant.
Dan
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
More information about the Leaplist
mailing list