automating folder creation & naming

Discussion in 'Mac Programming' started by peeluseeds, Mar 9, 2009.

  1. macrumors newbie

    Joined:
    Mar 9, 2009
    #1
    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!
     
  2. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    I am not the best with applescript or automator, but with shell:
    Code:
    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
     
  3. thread starter macrumors newbie

    Joined:
    Mar 9, 2009
    #3
    This is great! Exactly the type of thing I was hoping for.

    Thank you very much, Lee!
     

Share This Page