Hello!

I have this nice renaming script here.
It sanitizes badly named parts of files and folders.

But when I run it on my FAT32, dual boot transition partition (hehe), it causes
my computer (Pentium 4, 3,2 GHz) to freeze. I vaguely remember seeing some
message before it freezes saying "Locking from myself" or something like that,
this is not recorded into /var/log/messages.

It is very annoying actually because to rename a bunch of files I first have to
copy them to my UFS2 partition, run the script, and then copy them back to the
FAT32 partition.

Does this problem sound familiar to anyone?

Thanks!

Anyway here is the script.

#!/usr/local/bin/bash
#
#   Rename files and folders in MP3 releases.
#   $MERHABA: mp3_rename.sh,v 1.0 2007/11/11 15:09:05 kyrre Exp $
#

if [ $1 ]; then mv="echo"; else mv="mv"; fi

function do_folders () {

        for old in *; do

                if [ -f "$old" ]; then do_files "$old"
                elif [ -d "$old" ]; then

                new=`echo "$old" | tr "[:upper:]" "[:lower:]"`
                new=`echo "$new" | sed -e "s/ /_/g" \
                        -e "s/)//g" \
                        -e "s/-(/-/g" \
                        -e "s/_(/-/g" \
                        -e "s/(//g" \
                        -e "s/_-_/-/g" \
                        -e "s/---*/-/g" \
                        -e "s/___*/-/g" \
                        -e "s/\./_/g" \
                        -e "s/,/-/g" \
                        -e "s/'//g" \
                        -e "s/___*/_/g" \
                        -e "s/_-/-/g" \
                        -e "s/-_/-/g" \
                        -e "s/&/and/g" \
                        -e "s/\([-_]\)ft[_-]/\1feat_/g" \
                        -e "s/\([-_]\)featuring[_-]/\1feat_/g" \
                        -e "s/[][]//g"`

                if [ "$old" != "$new" ]; then $mv "$old" "$new"; fi

                echo "Renaming $old"

                cd "$new"; do_folders "$new"; cd ..

                else echo "Directory invalid."; fi

        done
}

function do_files () {

        old=$1

        new=`echo "$old" | tr "[:upper:]" "[:lower:]"`

        if [[ "$old" == *.* ]]; then

                extension=${new##*.}
                new=${new%.*}

                new=`echo "$new" | sed -e "s/ /_/g" \
                        -e "s/)//g" \
                        -e "s/-(/-/g" \
                        -e "s/_(/-/g" \
                        -e "s/(//g" \
                        -e "s/_-_/-/g" \
                        -e "s/---*/-/g" \
                        -e "s/___*/-/g" \
                        -e "s/\./_/g" \
                        -e "s/,/-/g" \
                        -e "s/'//g" \
                        -e "s/___*/_/g" \
                        -e "s/_-/-/g" \
                        -e "s/-_/-/g" \
                        -e "s/\&/and/g" \
                        -e "s/\([-_]\)ft[_-]/\1feat_/g" \
                        -e "s/\([-_]\)featuring[_-]/\1feat_/g" \
                        -e "s/^\([0-9]\{2,3\}\)_/\1-/g" \
                        -e "s/[][]//g"`

                new=`echo "$new"."$extension"`

                $mv "$old" "$new"; fi
}

do_folders .

_______________________________________________
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to