File renaming from a spreadsheet

I recently had to come up with a way to rename simple file names to more complicated file names from a spreadsheet on a Mac. It occurred to me that for those of you without Soundminer this technique might be useful for renaming SFX. Sometimes when you purchase a library, the file names are simply unique identifiers (like SD12321.wav), and the descriptive comments are included in an accompanying spreadsheet. By fiddling with the method below, you should be able to replace the original file names with the descriptions, allowing you to use the Finder to search them.     

  • Create a safety copy of your files

  • Make sure that the filenames are in column A and the descriptions are in column B

  • delete the other columns and save the spreadsheet as a .CSV

  • Create a new file in TextEdit and change your format to plain text (Format -> Make Plain Text) and enter the following script:

for details in `cat SPREADSHEET.csv`

do

OLD_NAME=`echo $details | cut -f1 -d,`

NEW_NAME=`echo $details | cut -f2 -d,`

echo "Renaming $OLD_NAME to $NEW_NAME"

mv $OLD_NAME $NEW_NAME

done

  • change SPREADSHEET in line 1 to be the filename of the spreadsheet with your names in it

  • save this text file as rename.sh inside the folder with the files you wish to rename

  • open Terminal and navigate to the folder with the files in it (type cd then drag the folder into the terminal, hit backspace once, then return)

  • type sh rename.sh

  • Profit.

 

NB: don’t forget to delete your safety backup of the exported files

NB: if you comment out the second last line with a hash #mv $OLD_NAME $NEW_NAME terminal will echo all the file changes for you without actually renaming the files.