Copy files to new folder structure

Discussion in 'Mac Programming' started by J.Henning, Mar 11, 2016.

Tags:
  1. J.Henning macrumors newbie

    J.Henning

    Joined:
    Oct 18, 2014
    Location:
    Stockholm | Amsterdam | Berlin
    #1
    Hello People!
    I got a gigantic task i would like to simplify with a bit of Applescript.

    Basically i'd like to move or copy a lot of files to a new folder structure.

    I have a few different folders with about 500-4000 jpg's, see image below.
    First image shows old structure, 2nd image show the new structure i would like to accomplish.
    [​IMG]
    [​IMG]

    What i would like to do is have a script loop through and take the first 4 characters of the filename and create a folder with that name in the location of my choosing. Then create a new folder in the parent folder called JPEG and copy all the files with that specific name to that folder.

    So far i have been able to automate the creation of folders and sub-folders.
    Any help is very much appreciated!

    Code:
    set loc to choose folder "Choose Parent Folder Location"
    
    repeat with i from 1 to 3
        set j to text -2 through -1 of ("0" & i as text)
        try
            tell application "Finder" to set targetFolder to make new folder at loc with properties {name:"61" & j}
            tell application "Finder" to make new folder at targetFolder with properties {name:"JPEG"}
            tell application "Finder" to make new folder at targetFolder with properties {name:"PSD"}
        end try
    end repeat
     
  2. J.Henning thread starter macrumors newbie

    J.Henning

    Joined:
    Oct 18, 2014
    Location:
    Stockholm | Amsterdam | Berlin

Share This Page