how to rename multiple files on the Mac

Discussion in 'Mac Programming' started by Darice Terry, Feb 12, 2008.

  1. Darice Terry macrumors newbie

    Feb 12, 2008
    I am in an online class and need to send a folder with 10 files to the teacher. The pc uses can use F2 and it will rename all the files with the one name of the folder. Does anyone know how to do this on the Mac Ibook?
  2. satyam90 macrumors regular


    Jul 30, 2007
    Bangalore, India
    if u are talking about windows "F2" for renaming, the same way u can accomplish the task on Mac is to right click (or ctrl+click) and select "Get Info" from the popup. In that u can rename the folder name.

    2nd method:
    Use "terminal" or "console" and go to that place of folder. use "mv (actual_name) (final_name)"

    Has my answer solved ur problem?
  3. JNB macrumors 604


    Oct 7, 2004
    In a Hell predominately of my own making
    Automator should do the trick for batch changes like that.
  4. krye macrumors 68000


    Aug 21, 2007
  5. ChrisA macrumors G4

    Jan 5, 2006
    Redondo Beach, California
    What exactly do you need to do. Yopu say "rename all the files with the one name of the folder" but I'm sure yo don't want want all the files to have the same name. You want each file to have a differnt name right?

    It's trivral in the terminal to change file names. The command of "mv" (just two leters) if you want to apply the mv command to multiple files then you might use mv in conjucion with "find" where you tell find which files need to be mv'd.
  6. ThierryL macrumors newbie

    Dec 2, 2009
    TotalCommander or Terminal

    The question is wrong; if you press F2 on a PC when selecting 10 files, the last filename of the selection will open, and there is no way you can automatically retrieve the name of the folder to add as a prefix or suffix to all 10 files.

    You can quickly do this using terminal as suggested by a previous post, but I would add that you can do multiple entries at the same time. Using TextWrangler (free) column mode, it's easy to create a bash shell script this way. As you may know, the terminal allows easy copy-paste on a Mac.

    If you're not script-oriented, you can use DiskOrder3 or TotalCommander. You can use TotalCommander on your Mac if you have VMware Fusion 3 in "unity" mode. So you run it as any Mac app.

    Hope this helps
  7. spice weasel macrumors 65816

    Jul 25, 2003
    +1. Automator is very easy to use, and will let you do batch changes to filenames. Look for the right workflow (should be something like "Rename finder items") under the "Finder" column in Automator. I'm not in front of my Mac right now, but it should be clear and easy to find.

    Drag the items you want to rename into the workflow pane in Automator. Then drag the Rename workflow script under that. Enter the filename you want to use and select the options (serial naming, etc.) Start the workflow and it will be done in a heartbeat.
  8. Big Dave macrumors 6502

    Nov 27, 2007
    Crestview, Fl
    You can also use the terminal to rename files.

    This is just a quick example of one use and hopefully with google or macrumors forums you can tailor it to your use.
    Let's say you have 5 files.
    You want to add the .txt extension to the file.
    Open an editor and enter the following in a file named script:
    for i in file*
    mv $i $i.txt #The mv command means move. Use cp to copy.

    Then make the script executable.
    $chmod +x script
    Then launch it
  9. peterhorner macrumors newbie

    Jun 26, 2010
  10. miles01110 macrumors Core


    Jul 24, 2006
    The Ivory Tower (I'm not coming down)
    Renaming utilities: (google them)

    Name Mangler
    Automator (not as good as the others)
  11. bwana macrumors newbie

    Sep 6, 2001
    liked the script.
    tried to modify it to remove the .txt extension of ALL files in a directory and make copies
    these files are named 1.txt , 2.txt , etc

    like so

    for i in *
    cp $i.txt $i #The mv command means move. Use cp to copy.

    got a LOT of errors for example

    cp: 990.txt.txt: No such file or directory

  12. jiminaus macrumors 65816


    Dec 16, 2010
    In this case $i with have the .txt on the end of it already. $i expands to 990.txt and so $i.txt expands to 990.txt.txt.

    You need to remove the trailing .txt from $i. The ${var%suffix} syntax will expand by removing suffix from variable var.

    Try using this cp command in your script.
    cp $i ${i%.txt}
  13. sero macrumors member

    Aug 28, 2008
    The best way to batch rename, IMO, is to drop the attached perl script in your bin and use regex. E.g.
    rename s/foo/bar/ *.txt

    Attached Files:

  14. bwana macrumors newbie

    Sep 6, 2001
  15. mikeschmeee macrumors 6502a

    Mar 9, 2009
    I know this is an old thread but thanks for this! I downloaded NameChanger and it worked! So fast. It renamed over just under 11,000 photos from my GoPro within a few seconds. Didn't make duplicates either just simple renamed.

    Thanks again!
  16. sm789 macrumors newbie

    Dec 9, 2011
    My problem!!!

    I am new here so I don't know if I am supposed to start a new post..

    My problem is as follows - My technical department generates an excel report every other day. Their system is automated so the file name is very long and goes like this Multiproduct Technical Report for 2011 12 06 by Jones.xls. I have hundreds of reports like this. Is there a way where I can change the names of all the files to say MTP 2011 xx xx.xls? Basically I want to preserve the unique date, remove "by XYZ" and modify (shorten) the "Multiproduct Technical Report" to something like "MTP"?

    Thank you for your help.

  17. LateOne macrumors newbie

    Mar 7, 2010
    S . Yorks
    I just thought I'd mention the (perhaps) obvious, that simple file renaming is available by putting Applescript in the menu bar via the Applescript Editor ( Utilities) preferences.

    Then, having selected your files to rename, select it in the menubar, choose Finder Scripts and there are options to Add (to) and Trim (from) file names.

    Not hugely sophisticated but it's done the job for me in the past.

    It nearly does the job that sm789 wants to do ( assuming multiple passes ) but I suspect there's an issue with the 'by Jones' bit because it won't always be Jones.
  18. subsonix macrumors 68040

    Feb 2, 2008
    If I understood this correctly, the only thing that needs to be preserved is the date, and make sure that the file name matches the form exactly so that no other files accidentally are renamed. In this case:

    "Multiproduct Technical Report for ${date} by ${name}.xls"

    Here's one approach with bash.

    # Check for arguments
    if [ $# -ne 1 ]
        echo "Arguments: <file to be renamed>"
        exit 1
    # Make sure that the file name is of the form: ""Multiproduct Technical Report for ${date} by ${name}.xls"
    test=$(echo "$1" | grep -P "^Multiproduct Technical Report for \d{4}\s\d{2}\s\d{2} by \w+\.xls$")
    if [ -n "$test" ]
        date=$(echo "$1" | cut -d" " -f5-7)
        [COLOR="SeaGreen"]echo "MTP ${date}.xls"[/COLOR]
        [COLOR="Red"]#mv "$1" "MTP ${date}.xls"[/COLOR]
    This just echoes the new name to the terminal to confirm that it works as intended. To rename the file you would have to move the # symbol from the red line to the green. Use at your own risk etc.
  19. MattiasN, May 27, 2012
    Last edited: May 27, 2012

    MattiasN macrumors newbie

    Nov 29, 2009
    Gothenburg, Sweden
    Interesting thread! Do you know how to rename files in multiple folders recursively where the renaming should be an added prefix that has been taken from the folder name?

    For example, to set the date as the prefix on each photo file in each date folder in the following folder structure?

    2012-01-01 (Folder contains jpg photo files taken on the 1st of Jan 2012)
    2012-02-28 (Folder contains jpg photo files taken on the 28th of Feb 2012)
    2012-03-15 (Folder contains jpg photo files taken on the 15th of Mar 2012)

    It would be even more fantastic if it was possible to shorten the inserted date prefix to just "YYMMDD_" instead of insert the original full date and the dashes "YYYY-MM-DD_".

    The original file name is "DSCF12345.jpg"
    The renamed file name should be: "120101_DSCF12345.jpg"
  20. MacBpro macrumors member

    Mar 30, 2011
    Chicago, IL
    Cant believe why apple make it so complicated for some frequently use functions!!!! It sounds like we are going back to the apple 2 age... need to memorize all the commands!!!

    Do they have any idea there is a big room for them to improve and make it really USER FRIENDLY!!!????:mad:

    really makes me sick!!!
  21. gnasher729 macrumors P6


    Nov 25, 2005
    Frequently used? Seriously? I'm in my 29th year using Macs and have never, ever found any need to do this.
  22. ghellquist macrumors regular

    Aug 21, 2011
    Stockholm Sweden
    And if you start the terminal window, there are lots and lots of variations on how to do the renaming. Lurking in there is a full Unix system, with all of the commands either already installed or easily downloadable.

    Learning to use the shell commands or perl or similar programming languages will take a bit of effort but can be very worthwhile.

    There are of course graphical programs doing some of these things, but if your exact requirement is not handled you are generally off on your own. Then shell is your friend.

  23. OlandeseVolante, Mar 19, 2013
    Last edited: Mar 19, 2013

    OlandeseVolante macrumors newbie

    Feb 8, 2011
    Turin, Italy
    Hello! :)

    I think I'm having the same problem of Darice Terry, but I'm guessing, since he's never replied again to his own thread.

    Just today I was looking for a friendly way to rename multiple files with the same name (different extensions of course!) on Mac OS X Lion, but I haven't found any yet.

    Let me explain. With Windows 7, in order to rename two files at once, for example an AVI file with a Subtitles file:


    I can select them both, press F2 (or Right click > Rename), and type the new name once. The result will be:


    With OS X, I have to click on the first file and type the new name, then click on the second file and do the same.

    Is there an easier way, not involving scripting? I can't believe that Windows can be more user friendly than OS X :)

  24. gnasher729 macrumors P6


    Nov 25, 2005
    You're in the programming section.
    Terminal, man mv
  25. OlandeseVolante macrumors newbie

    Feb 8, 2011
    Turin, Italy
    Sorry I didn't know, I ended up here by searching "how to rename multiple files" with Google :)

    So you confirm that there's no way to do that only with the GUI?


Share This Page