A while back I wrote a post on renaming FLAC files to include their associated disc numbers. For example, if you have a file from disc 1 named “01 – Track Name.flac” my script would change it to “01.01 – Track Name.flac”.
This updated version of the script allows the user to enter the path to the folder needing files renamed and the associated disc number.
I think this is a slightly simpler method than my previous method for using this script. You can read about the original script here.
Here is the current script:
## #!/bin/bash # by JamesIsIn from JamesIsIn.com # Do something nice today. # Prepend album number before track numbers # 01 - Track Name.flac becomes 01.01 - Track Name.flac echo echo "This script will change FLAC file names based on a containing folder and a disc number which you supply." echo "Example: "01 - Track Name.flac" becomes "01.01 - Track Name.flac"" read -p "I will require the path to the containing folder: " if [ -d "$REPLY" ]; then printf "I have confirmed this is a directory.nn" directory="$REPLY" else printf "I cannot find this directory.nn" exit 1 fi read -p "Which disc number, please (01 through 99): " # add test for 01-99 printf "%bnn" "I will prepend $REPLY to all FLAC files in: $directorynn" newname=$REPLY read -p "Press <ENTER> to continue (ctrl-c will abort)." echo cd "$directory" rename "s/^/$newname./" *.[Ff][Ll][Aa][Cc] #
This version also handles FLAC extensions in any case (flac=FLAC=FlAc &c).
If I make any updates, I’ll likely just change this post. As such, I should say that this current version is current as of 8 March 2010.
Have fun with that.