Script file to rename files

Discussion in 'Mac Basics and Help' started by Keith-Jaw, Aug 11, 2015.

  1. Keith-Jaw macrumors newbie

    Joined:
    Aug 11, 2015
    #1
    I need to add a suffix to a whole load of files, to make them useable, but it's a pain doing this one at a time.

    At one time I knew how to create a batch file in MS-DOS. Something like: name *.* as *.gsm

    Is there a similar technique for OS-X. If so, how to run it?
     
  2. ocabj macrumors 6502a

    ocabj

    Joined:
    Jul 2, 2009
    #2
    Code:
    man find
    Examples

    Code:
    # change all *.doc files in current dir, non-recursively, to *.txt
    find . -maxdepth 1 -type f -name "*.doc" -exec bash -c 'mv "$0" "${0%\.doc}.txt"' {} \;
    
    # add .txt extension to all files in current dir, non-recursively
    find . -maxdepth 1 -type f "*.txt" -exec bash -c 'mv "$0" "${0}.txt"' {} \;
    
     
  3. Keith-Jaw thread starter macrumors newbie

    Joined:
    Aug 11, 2015
    #3
    Thanks - but I need a bit more:

    After I've generated the script file, how do I run it? Is there something like a DOS window?
    How do I 'log on' to the current dir, so that the system knows what the current directory is?
     
  4. ocabj macrumors 6502a

    ocabj

    Joined:
    Jul 2, 2009
    #4
  5. Keith-Jaw thread starter macrumors newbie

    Joined:
    Aug 11, 2015
    #5
    Wow - a lot more complex than DOS, obviously.

    Thanks for your help!
     
  6. CoastalOR macrumors 68000

    CoastalOR

    Joined:
    Jan 19, 2015
    Location:
    Oregon, USA
    #6
    It's not a script and it's not a free app ($19.95), but I like "A Better Finder Rename" app.
    Here is a link to the site:
    http://www.publicspace.net/ABetterFinderRename/
     
  7. Taz Mangus macrumors 68040

    Taz Mangus

    Joined:
    Mar 10, 2011
    #7
    • From your web browser copy the text for the script.
    • Open the terminal application in the Applications/Utilites folder.
    • In the terminal app window enter:
      • vi <name to call script>.sh
      • Press i-keyboard key.
      • Press Alt-v keyboard keys.
      • Press ZZ keyboard keys. Make sure both letters are uppercase Z.
    • In the terminal app window enter:
      • chmod 755 <name that you called the script>.sh
    • To run the script, enter the following in the terminal app window.
      • ./<name that you called the script>.sh
    That is how you create the script which will reside in your user account root directory. So let's say that you want to create the script called renamefiles.sh and the folder where the files reside in your user account named Documents.
    • From your web browser copy the text for the script.
    • Open the terminal application in the Applications/Utilites folder.
    • In the terminal app window enter:
      • cd ~/Documents
      • vi renamefiles.sh
      • Press i-keyboard key.
      • Press Alt-v keyboard keys.
      • Press ZZ keyboard keys. Make sure both letters are uppercase Z.
    • In the terminal app window enter:
      • chmod 755 renamefiles.sh
    • To run the script, enter the following in the terminal app window.
      • ./renamefiles.sh
     
  8. MacUser2525, Aug 11, 2015
    Last edited: Aug 11, 2015

    MacUser2525 macrumors 68000

    MacUser2525

    Joined:
    Mar 17, 2007
    Location:
    Canada
    #8
    I like NameChanger a free program that has a prepend and append to add to the beginning or end of a file name along with many other renaming options. Have used it for years without problems and the best part as already mentioned it is free.

    http://mrrsoftware.com/namechanger/

    Another one is name mangler which I use for its droplet function where I drag and drop onto a droplet to clean out the garbage special characters and spaces from file names. I do believe they have went to a paid model though in the later versions of it, last free version I have installed still does the trick though.

    http://manytricks.com/namemangler/

    Edit2: Now I think about it more not sure the NM does an append function though a replace of current extension with a current extension plus new would work with it.
     
  9. Keith-Jaw thread starter macrumors newbie

    Joined:
    Aug 11, 2015
    #9
    Another option occurs to me. These files are on a network, and another MAC on that network has parallels. So maybe it would be simpler to create and run a batch file in good old DOS. If I can remember the syntax!

    Alternatively, these other programs might do the trick.

    Many thanks for all your suggestions, guys.
     

Share This Page