SOLVED Script to move files into named folders

Joined
Feb 7, 2020
Messages
4
Reaction score
0
Hello,

I wonder if someone can help me with a script to move files into existing (named)folders:

I have 15 jpgs in ONE folder on my desktop.

I need to move EACH 15 of those files into named folders to a network location path.
Ex:
012345_ 01.jpg into folder named: 01_asset_rgb_100px

0123456 02.jpg into folder named: 02_asset_rgb_200px

0123457_ 03.jpg into folder named: 03_asset_rgb_300px

0123458 04.jpg into folder named: 04_asset_rgb_400px

0123459 05.jpg into folder named: 05_asset_rgb_500px and so on...to asset folder 15.
 
Joined
Jan 25, 2017
Messages
1,266
Reaction score
100
Is there a reason that some of the filenames have an underscore in them and some do not?
 
Joined
Jan 25, 2017
Messages
1,266
Reaction score
100
The script I have just done for my task works OK. I have a folder called mixed full of images some are 300X200px and prefixed s_ others are larger prefixed l_ the others are unprocessed and have no prefix. My script takes the s_ files and puts them in a folder called small and takes the l_ files and puts them in a folder called large the other files are unmoved. I think it will be possible to extend this idea to cover your scenario and I am currently working on this. below is my current script, it may point you in the right direction.

Code:
set source to (path to desktop folder as text) & "mixed:"


set destination to (path to desktop folder as text) & "small:"


set destination2 to (path to desktop folder as text) & "large:"





tell application "System Events"


    set the_names to name of files of folder source whose visible is true


end tell


repeat with a_name in the_names


    set clef_key to text 1 thru 2 of a_name


    if clef_key is in {"s_"} then


        


        set orig to quoted form of POSIX path of (source & a_name)


        set target to quoted form of POSIX path of (destination)


        do shell script "mv " & orig & space & target


    else


        if clef_key is in {"l_"} then


            


            set orig to quoted form of POSIX path of (source & a_name)


            set target to quoted form of POSIX path of (destination2)


            do shell script "mv " & orig & space & target


            


        end if


    end if


end repeat
 
Joined
Jan 25, 2017
Messages
1,266
Reaction score
100
I have set this one up to do 5 of the 15 files, but the principle is the same for any number of files, it just needs some more else if statements.

You should be able to cut and paste this into the script editor.
Code:
set source to (path to desktop folder as text) & "mixed:" ------------------Source folder


set destination1 to (path to desktop folder as text) & "01_asset_rgb_100px:" --------- Set up destination folders..


set destination2 to (path to desktop folder as text) & "02_asset_rgb_200px:" --------Set up  destination folders..


set destination3 to (path to desktop folder as text) & "03_asset_rgb_300px:" --------Set up destination folders..


set destination4 to (path to desktop folder as text) & "04_asset_rgb_400px:" ------- Set up destination folders..


set destination5 to (path to desktop folder as text) & "05_asset_rgb_500px:" --------Set up destination folders..


tell application "System Events"


    set the_names to name of files of folder source whose visible is true


end tell


repeat with a_name in the_names # Loop through filenames


    set clef_key to text 8 thru 10 of a_name


    if clef_key is in {"_02"} then


        set orig to quoted form of POSIX path of (source & a_name) --------------- Put file in designated folder


        set target to quoted form of POSIX path of (destination2)


        do shell script "mv " & orig & space & target


    else


        if clef_key is in {"_03"} then


            set orig to quoted form of POSIX path of (source & a_name)


            set target to quoted form of POSIX path of (destination3)


            do shell script "mv " & orig & space & target


        else


            if clef_key is in {"_04"} then


                set orig to quoted form of POSIX path of (source & a_name)


                set target to quoted form of POSIX path of (destination4)


                do shell script "mv " & orig & space & target


            else


                if clef_key is in {"_05"} then

             set orig to quoted form of POSIX path of (source & a_name)


                    set target to quoted form of POSIX path of (destination5)


                    do shell script "mv " & orig & space & target

     
                end if


            end if


        end if


    end if


end repeat



repeat with a_name in the_names ----------------------------------- Special case as file name is 1 character shorter than the others


    set clef_key to text 7 thru 9 of a_name --------------------------- Would need another section if filename was longer


    if clef_key is in {"_01"} then



        set orig to quoted form of POSIX path of (source & a_name)


        set target to quoted form of POSIX path of (destination1)


        do shell script "mv " & orig & space & target


    end if


end repeat
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top