10/30/09
6:59 am

MacMost Now 312 : Batch Rename Multiple Files

Learn how to rename a batch of files using Automator in Snow Leopard. You can quickly and easily create a workflow that will allow you to select a group of files or a folder and rename the files replacing or adding text, adding numbers or the time or changing the file extension.

Video Transcript
Hi, this is Gary with MacMost Now. On today's episode, lets learn how to batch rename files.
So one of the problems switchers have when coming from Windows is that it's not very easy to batch rename files in Mac OS X. In Windows there's an F2 key that allows you to do a bunch of different things. But in Mac OS X Snow Leopard you can use Automator to do that and much more. Lets take a look.
So look in your applications folder for Automator. Now when you first run it you'll get asked to choose a template. Just choose the default, which is workflow'. This gives you a blank workflow to the right. On the left we can choose from various different actions that Automator can do. You can search for one or you can click on a category here. Lets look in Files and Folders, and one of the first items is Ask For Finder Items'. We're going to select that and we're going to drag that into this area here. Now you get to define some things, like what the prompt says, where to start at the desktop and in this case we want to allow multiple selections of files. Of course the whole point of batch rename is select multiple files and have them all renamed. So the next thing we want to do is we want to rename these files. Lets do a search here for rename', and we can see there is an item here that matches the Rename Finder Items'. If we drag that underneath this one we'll get to add it. Now it's going to give us a warning about this particular one that it's going to basically rename these items and there's also a way for us to copy the originals so we don't destroy the originals with the new ones that have been renamed. We don't want to do that in this case. We're just going to go ahead and rename the files right away without any problem. So now we've got two steps here in the workflow; the first is to choose multiple files and the second is to do something with them. So we can do various things in a rename. We can add a date or time, we can add text, change the case, make sequential, replace text or name a single item. Lets start with a simple one, like replace text. We're going to go and look for this text, the word audio' in the full name of the file and we're going to ignore case there, and we're going to replace it with this word, sound'. Now we don't have to create a full workflow and save it for future use; we can just run this one here just this one time, which is what we're going to do. We're going to run it, and on the desktop I've got a folder called Test'. In there I've got a bunch of files name audio' with a number after it. By selecting all of these I've selected the first one, shift and selected the last one, select them all I'm going to choose them all and it's going to go ahead, it's going to tell me what it did, and if I go ahead and look in this folder now I can see that it indeed renamed all these files from audio003' to sound003.wav'. So I've successfully did a batch rename replacing text.
Now we can try different things, like instead of replacing text, for instance, we can make them sequential. Now when we make them sequential there's a lot of different things we can do. For instance, we can go ahead and add a number to the existing name or add a number to the new name. So lets rename all the files that we're going to select and just rename them with a word and then place the number after the name, start at number one, separate by nothing so there's no dash or space or anything like that and we can make all the digits, all the number two digits long or we can leave that unselected. We'll go and we'll run this. We'll select the same folder here, all the sounds in it, and do it. Now we look in the folder and we see the results are all the files have been renamed media' and a number, .wav, sequentially.
Other things you can do include just simply adding text, either after or before or as the extension to a file. We can go and add the day or time, and it gives you also options. Like you can take the create a date', modify date', last opened' or the current date', you could change the format it's in, separators, things like that. You can go ahead and change the case, the base name or the entire name or the extension. Lower case, upper case or titles for, capitals for each word.
Now if you think you're going to do this pretty often you can go ahead and save this workflow; you can save it as either a workflow to be opened up in Automator, which will allow you to edit and change things. You can also save it as a stand alone application, which then you can just run instantly, but you won't be able to change these options.
Another way you could do this is you could actually use the Get Folder Contents' to get the entire contents, all the files in a folder. So the first thing you want to do is Ask For Folder Items' again, but this time set type to be Folders and not allow multiple selection. Then you use Get Folder Contents' below that. So this will ask for a folder, this will go ahead and then ask, get all the files in that folder, and then you can go ahead and do a rename here, and it will rename all of the files in a folder, so you don't have to select all the items. This could be a little less versatile, but if it's what you need to do all the time it's a little quicker to use.
So that's how you batch rename files in Mac OS X using Automator. Til next time this is Gary Rosenzweig with MacMost Now.

Comments: 18 Responses to “MacMost Now 312 : Batch Rename Multiple Files”

    Randy Clark
    11/2/09 @ 3:46 pm

    Great Automator tip! I’m a long-time Mac user, but have never gotten into using AppleScript/Automator but this might inspire me to finally jump into it. One related question to this tip: is there any way either thru Automator or some 3rd party Mac apps to re-name a bunch of files RANDOMLY? I frequently add new photos to my digital frame’s SD card, and while the frame supposedly has a random-display mode, it’s never worked. I’d like to take my photo files for the digital frame and randomly rename the files (using number prefixes). I’ve searched several times over the past few years to find some way to easily accomplish this on a Mac, but failed to turn up any viable options. Any ideas?

      11/2/09 @ 3:48 pm

      You should be able to do that with AppleScript, yes. But I’m not sure of the exact code off the top of my head, sorry.

      Lorelei
      12/16/09 @ 1:24 am

      I was looking for a way to do the exact same thing, for the same reason; I found this in searching for it. Failing, though, I wrote the AppleScript to do it. I thought I’d share, in case you were still looking for a way:

      (*
      This is a script to append random numbers to the beginnings of file names. Originally created for the purpose of randomizing pictures for adding to a digital frame.

      It will, as the warning says, rename original files rather than creating copies. But hey, it warns you first!

      Written 16 Dec 2009, by LoreleiF
      Written in Snow Leopard, but should be good at least down to Tiger.
      *)

      tell application “Finder”

      set theFolder to (choose folder)

      display dialog “WARNING: This will NOT create copies of your files – it will rename the originals. Continue?” buttons {“Yes”, “No”} default button “No” with icon caution

      if the button returned of the result is “Yes” then
      set theFiles to (get every item of theFolder)

      repeat with i from 1 to count of theFiles

      set oneFile to item i of theFiles

      set the name of oneFile to ((random number from 1 to 1000) & (the name of oneFile) as text)

      end repeat

      end if

      end tell

    Dick Franks
    11/8/09 @ 9:15 pm

    Very useful!

    On a recent trip my wife and I each took 400 photos using our two cameras. Now I can place the 800 photos in the same folder without a Duplicate Name conflict, such as IMG_1234 being created by each camera. It also allows quick identification of the author.

    Like Randy, I’m inspired to get further acquainted with Automator.

    Scotty
    12/22/09 @ 9:35 pm

    Hi. Before Snow Leopard, I was able to have a simple renamer action appear in my Finder right-click menu.

    Since I updated to Snow Leopard, I don’t see that option. What happened, and how do I get it back?

      12/22/09 @ 10:55 pm

      Just select a file and press the Return key on your keyboard. Alternatively, you can select the file, wait a second so it isn’t a double-click, and click on the name of the file. Both will then allow you to edit the name.

        Scotty
        12/23/09 @ 8:04 am

        What I meant was, the renamer was only one of the Automator functions I had on my right-click menu.
        It was Right-Click/More/Automator/renamer (or something similar)

        I had a few functions I liked having in that menu, but I don’t get ‘More’ on the right click menu any more.

        Thanks for the reply. I’ll hang up and listen.

          12/23/09 @ 8:16 am

          It sounds like maybe you had something installed that gave you that functionality? Perhaps you installed a piece of third-party software that gave you some functions like that.

    Jefe del Fresco
    3/3/10 @ 7:31 pm

    Awesomely helpful tutorial. I didn’t even know I had something called Automator. Gary, you just saved me a tedious hour today, and many more in the future. Thanks!

    bronek
    4/8/10 @ 2:21 pm

    VERY USEFUL!! THX!!!

    John Forstall
    5/28/11 @ 7:54 am

    Excellent tutorial

    Hugh
    6/10/11 @ 8:06 am

    Great tutorial Gary, very helpful. Out of interest is there any was of setting automator to prompt for the user to enter the new filename text as part of the workflow rather than having to edit the workflow itself each time? Many thanks

      6/10/11 @ 9:39 am

      Yes. You can ask for text, you can ask to find a file, all sorts of things. Look through the Automator actions and experiment.

    Phil Jordan
    2/3/12 @ 4:06 am

    Hi Gary

    Love your newsletter, and your archive of videos is a real comprehensive library of tutorials that I have benefitted from many times. Thank you. With this Automator sequence, can you ask it to look into folders and sub folders? Rather than having to select files within one folder at a time?

    I need to batch rename approx 1.2TB of audio files all grouped into artist/title folders.

    Thanks
    Phil

      2/3/12 @ 8:16 am

      Im pretty sure there is no way to do that as an Automator sequence. But as AppleScript it should be possible. But not easy, unless you are a programmer and have either experience or time. Lots of steps and a big learning curve.
      Maybe purchasing a batch rename application is the more efficient way to do it.

      Aaron
      5/11/12 @ 4:31 pm

      Phil, It’s really too bad he didn’t cover recursion. Oh well. Back to google.

    Phil Jordan
    2/7/12 @ 4:24 pm

    Hi again Gary

    Thanks for your quick response. I thought I should report back that I have persisted with this and I think I have found a work-around. So for anyone else doing something similar to me, you can try this:

    Select the Automator processes as per Gary’s video, click ‘Run’ and instead of choosing files within a folder, spotlight the file extensions within the master folder (in my case I spotlight “.wav” within the master folder “Music”), than select all.

    There are approx 24,000 tracks on my NAS drive (all CD quality or above), so my MacBook Pro struggled to handle the task. I am currently running it through an iMac which seems to be working, but it may take a couple of days more!

    Kind regards and thanks again for your videos!

    Cheers
    Phil

    Dave
    2/14/12 @ 7:28 am

    Worked for me with Lion (02/2012) but I had to replace all the quote marks with quote marks from my keyboard (SHIFT+”) since the existing code quote marks are ‘out-of-bounds’ for Lion.

Comments Closed.