-
Mac Addict
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
-
04-21-2005 02:32 PM # ADS
Google Adsense
-
Apple Genius
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".
-
Mac Addict
Cool, exactly what I was looking for 
Thank you!
-
or you can wait for tiger's automator.
-
Mac Fanatic
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.
-
Super Moderator
Or a more elegant solution is to use File buddy. Simply drag a folder to the File buddy app and right click to rename.
Bookmarks