PDA

View Full Version : automating folder creation & naming




peeluseeds
Mar 9, 2009, 06:47 PM
Hi everyone,

I'm trying to figure out a way (with Automator, ideally) to have a script look through a folder and create a new folder for each item. for example:

-search through folder for all files with EPS extension
-for each EPS file, create folder with name of the EPS file (minus extension)
-move EPS file into created folder.

I hope automator can do this!

Thanks for the help!



lee1210
Mar 9, 2009, 07:23 PM
I am not the best with applescript or automator, but with shell:

ls *.eps | awk -F'.eps$' '{print "mkdir "$1"; mv "$0" "$1"/"}' | sh


In general, always back up anything before you run a script you write, or you get from an untrustworthy source (like the internet), etc.

ls *.eps will give you a list of files that end with .eps. The awk command tokenizes on .eps<end of line>, and prints "mkdir <filename without eps>; mv <filename> <filename without eps>/", and sending that to sh will execute that command. You can accomplish the last bit using system() in awk instead, but i always like to print and see what's going to happen first, and it's always easy to just pipe it to sh instead of changing it to system.

-Lee

peeluseeds
Mar 9, 2009, 08:45 PM
This is great! Exactly the type of thing I was hoping for.

Thank you very much, Lee!