So I got this awesome Japanese Harry Potter audiobook and I ripped it in .m4a format accidentally, instead of .m4b, which would show up as a book on my phone instead of music.
Rather than re-rip the 10 discs I decided to simply rename them. This proved to be quite annoying in the Mac gui. You have to click the name, hit space, click the end of the line, change the extension, confirm that you want to change it... for every file...
I decided to take a more direct approach and use terminal. To rename in terminal you just move the file to the same directory and change the name.
So it was something to the effect of:
mv 01\ Audio\ Track.m4a 01\ Audio\ Track.m4b
but doing it this way meant I had to manually change the number every time by holding the left arrow till I got to the number and then change it...
Obviously I had to automate this process, so I threw together a little bash script to do all this for me.
<CODE>
#/bin/sh
V=1
while [ $V -lt 10 ]; do
echo renaming Number $V
mv 0$V\ Audio\ Track.m4a 0$V\ Audio\ Track.m4b &
let V=$V+1
done
if [ $V = 10 ]; then
while [ $V -lt 30 ]; do
echo renaming number $V
mv $V\ Audio\ Track.m4a $V\ Audio\ Track.m4b &
let V=$V+1
done
fi
</CODE>
This little beauty starts at 01 and changes the name of each of them, sequentially, until 29.
This takes about .3 seconds per folder and worked flawlessly!
The tricky bit, that looks a little redundant at first, was to get it to count 01, 02, 03, etc... Which is why there is the check to see if it's 10 or less :)
I hope this does somebody good lol I love it!