How can I batch rename filenames to match a list from another folder (or text file) on a Mac?
November 7, 2011 7:04 AM   Subscribe

How can I batch rename filenames to match a list from another folder (or text file) on a Mac?

I'm in the process of replacing low quality versions of mp3s in my iTunes library with higher quality versions. The easiest way to do this is to just swap the mp3 file over in the source folder in iTunes, then choose "get info" to force iTunes to update the song. This way I don't lose my ratings, play counts or other metadata. However, the new mp3 filenames aren't named in the same way that iTunes' are.

Is there a utiltiy/tool/script to rename a folder full of files to match another folder? ie, copy a list of files/filenames then paste them over another list to rename them. I'm using a Mac.

I've got a huge task ahead of me to update all my old files, and if I could do this, it would save an incredible amount of time.

Cheers!
posted by snarkle to Computers & Internet (11 answers total)
 
In what format is your list that says which new filename corresponds to each old filename?
posted by flabdablet at 7:11 AM on November 7, 2011


The only list I have at the moment are both folders containing the files. They could be copied to an intermediary text file/application/spreadsheet easily though.
posted by snarkle at 7:15 AM on November 7, 2011


I don't know how geeky you are or want to be, but this is where I break out Perl!

If you get the filenames into a text file, say mappings.txt, that has semi-colon separated filenames (chosen because in MP3 files you could have all sorts of weird characters, including single quotes and spaces), you can do something like:
perl -anl -F\; -e 'rename $F[0], $F[1]' mappings.txt
This says "run Perl, using autosplit mode (-a), provide an implicit loop which reads the file (-n), and automatically deal with line endings (-l). Make the separator for autosplit a semicolon (-F\;) (and the backslash is necessary here because semicolon means something to "bash", the command line)".

This reads "mappings.txt", splits the lines along the semi-colon into the array "@F", which we can access with $F[0] and $F[1], so for each line we can say execute (-e ...) a rename command of the first to the second.
posted by straw at 7:32 AM on November 7, 2011 [2 favorites]


The only list I have at the moment are both folders containing the files.

So how do you know which file in the replacements folder corresponds to any given file in the old folder?
posted by flabdablet at 7:37 AM on November 7, 2011


I'm lazy and don't like messing with the command line. Assuming that the files are all correctly tagged, I'd use Song Sergeant (which I've already bought for $20) to merge the two sets of MP3s inside iTunes. It should automatically prefer the higher-quality MP3s, but you get a chance to review it manually before you make any changes.

It's not exactly what you're looking for and it does cost $20, but I know it works for the problem you're trying to solve.
posted by immlass at 8:20 AM on November 7, 2011


You might take a look at a Mac program called Name Those Files. I used it recently to rename a ton of photos, and it was very fast and easy to use. I believe it will do what you need to do.

What's better is that they offer a 7 day, fully functional trial download. If you like it, the cost is only $18.95.
posted by konig at 4:11 PM on November 7, 2011


Question is, how do you make the list of filename mappings... From "High Quality Folder/song name 1.mp3" -> "Original Folder/song 1 with different name.mp3".

The easiest case is when it's a typical Album folder with numbered songs:
Low Folder
 01 - track01.mp3
 02 - track02.mp3
...
High Folder
 01 - track01 high quality.mp3
 02 - track02 high quality.mp3
Then you can just directly map the tracks from folder to folder in natural order.

There are half a dozen or so ways to go about this depending on the organization of your files, whether or not the files have special characters in their name ("01.mp3" vs "Foo? [dance mix](busta).mp3").

If the folders are in-order like this,
$ find "Low Folder" > low.lst
$ find "High Folder" > high.lst
$ paste -d\; high.lst low.lst > mappings.lst
Will get you the list in the "High Folder/01 - title.mp3;Low Folder/01 - title01.mp3" format like straw mentions.

If it's anything more complicated, I would usually start by making a mappings file like this:
low folder/song1.mp3
high folder/01-song1title.mp3

low folder/song2.mp3
high folder/02-song2title.mp3
With low/high on separate lines, with a blank line between them. This is easier to check by eye than having both source/destination on the same line and easy to parse in Perl (there's a magic blank-line-separated input thing).
posted by zengargoyle at 4:12 PM on November 7, 2011 [1 favorite]


I don't have a specific answer, but have you messed around with Automator? I use it quite a bit for resizing and renaming files -- and there is a renaming function. It might be a good starting point for getting you what you want. As always, back up your files and experiment with a small test group before pulling the trigger on your entire collection. Good luck!
posted by slogger at 5:47 PM on November 7, 2011


Thanks heaps for all your answers everyone. I'm going to test out a few options & see how I go. It's a lot of work!
posted by snarkle at 4:34 PM on November 13, 2011


Sorry I'm late to the party but I just came upon this thread. Looks like you can do this in the newer versions of Bulk Rename Utility. You upload a text file with your new and old file pairings

oldname1.mp3|newname1.mp3
oldname2.mp3|oldname2.mp3

I use BRU a lot and it's very easy to use.
posted by radioamy at 9:22 AM on December 1, 2011


Less so on the OP's Mac though, I'd expect.
posted by flabdablet at 9:15 PM on December 1, 2011


« Older How easy is it to brew non-alc...   |  My boss has asked me to write ... Newer »
This thread is closed to new comments.