Hello and welcome to our community! Is this your first visit?
Register

Results 1 to 6 of 6

Thread: Renaming Files

  1. #1
    Mac Addict randytamayo's Avatar
    Join Date
    May 2004
    Location
    Melbourne, AU
    Posts
    1,669

    Default Renaming Files

    Guys,

    How do I rename the files (all files) in a folder in OSX/Terminal.

    Example:
    Folder1
    File1
    File2
    File3
    File4
    File5
    File6

    Rename to:
    Folder1
    File1.afx
    File2.afx
    File3.afx
    File4.afx
    File5.afx
    File6.afx

    Same with Folder2 and so on...

    I have to rename close to 2000 files

    In MS-DOS it would be:
    REN Folder1\* *.afx

    Merci!
    Randy

  2. # ADS
    Google Adsense

    Join Date
    Always
    Location
    Advertising world
    Posts
    Many




     

  3. #2
    Apple Genius Gomi's Avatar
    Join Date
    May 2004
    Location
    Baguio
    Age
    35
    Posts
    2,170

    Default

    cd to the directory with your files. After backing them up first, of course.

    Do this:

    % foreach file (*.X)
    > mv $file `basename $file .X`.Y
    > end

    Now then. This will probably confuse anyone who hasn't used the CLI in OS X much. % is the command prompt. "foreach" is essentially a shell scripting thinger that does stuff. You have to type end to make it go or get out of it. The > characters are prompts for data that foreach wants. You want to give foreach data. Really. You do. And you want to be damned sure you spell everything correctly!

    *.X can be anything- for my needs, it was *.html . * is a wildcard- *.html would mean "everything ending in .html", simply.
    Basename strps off the extensions. Anything.html becomes Anything. Sticking it in between `these things` strips everthing off.
    The ` character confused me- I thought it was an apostrophe. It's not. It's the thing you get when you press the ~ key without pushing shift first. I've been using computers since I was 6 and this is the first time I've needed that character!
    .Y is your destination extension- whatever you want. .X is your base.

    Here's the thinger set up to make .html into .php .

    % foreach file (*.html)
    > mv $file `basename $file .html`.php
    > end

    When you hit enter after entering in the "end" in the third line, the terminal putts away for a moment while it's doing its thing. If your command line fu is strong, you already know how to do this, and configure to be verbose. The changes are updated within Aqua right after it's all done- it's kind of cool to open a window and watch 67 files "jump".

  4. #3
    Mac Addict randytamayo's Avatar
    Join Date
    May 2004
    Location
    Melbourne, AU
    Posts
    1,669

    Default

    Cool, exactly what I was looking for

    Thank you!

  5. #4
    hannibal's Avatar
    Join Date
    Apr 2004
    Posts
    3,383

    Default

    or you can wait for tiger's automator.

  6. #5
    Mac Fanatic alistair's Avatar
    Join Date
    Feb 2005
    Location
    Makati
    Age
    38
    Posts
    928

    Default

    I believe the back tick (`) characters work in *nix thusly: any text enclosed in back ticks like so `ls` are executed by the shell, and it's console output inserted in its place in the original command.

  7. #6
    Super Moderator Kenneth's Avatar
    Join Date
    Apr 2004
    Age
    35
    Posts
    3,128

    Default

    Or a more elegant solution is to use File buddy. Simply drag a folder to the File buddy app and right click to rename.

  8.   



 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •