Automator/Applescript to move files to folders

Hey all i have a huge batch of files that need to get grouped into folders. I figured out how to automate the folder creation but i can't figure out how to automatically move the files into the designated folders. here is what im working with:

User uploaded file

Basically each folder has 3 images that have to go into it. i hope to do this in a generic manner so when i get another batch of these in the future i can use the same script/action. Any help will be greatly appreciated.

iMac Pro, iOS 11.4

Posted on Jun 20, 2018 10:37 AM

Reply

Similar questions

9 replies

Jun 20, 2018 12:58 PM in response to Kyexvii

Put it around only the move line, or run:


tell application "Finder"

set this_folder to (choose folder) --do not change this line

set the_files to (get files of this_folder)

repeat with this_file in the_files

set the_name to name of this_file

set the_short_name to items 1 thru 8 of the_name as string

if exists folder the_short_name of this_folder then move this_file to folder the_short_name of this_folder

end repeat

end tell


(161751)

Jun 20, 2018 11:32 AM in response to Kyexvii

Assuming the logic is that the folder name is essentially a prefix to the file names, you can do something like this in AppleScript:


use AppleScriptversion "2.4" -- Yosemite (10.10) or later

use scripting additions



set topFolder to (choose folder with prompt "Select the top-level folder")


tell application "Finder"

set folderList to every folder of folder topFolder

repeat with eachFolder in folderList

set folderName to name of eachFolder

set filesToMove to (every file of folder topFolder whose name begins with folderName)

if (count of filesToMove) > 0 then


movefilesToMovetoeachFolder

end if

end repeat

end tell

Jun 20, 2018 12:16 PM in response to Niel

ignoring application responses

tell application "Finder"

set this_folder to (choose folder) --do not change this line

repeat with this_subfolder in (get folders of this_folder)

set folder_name to name of this_subfolder


move (every file of this_folder whose name starts with folder_name) tothis_subfolder

end repeat

end tell

end ignoring


This prevents set this_folder from working, did i put it in the wrong place?

Jun 20, 2018 5:12 PM in response to Kyexvii

Will work if the folder names are less then 8 characters.


tell application "Finder"
    
    set this_folder to (choose folder) --do not change this line
    
    set the_files to (get files of this_folder)
    
    repeat with this_file in the_files
        log "this_file is " & this_file
        
        set the_name to name of this_file
        log "the_name is " & the_name
        -- problem line
        set minimumValue to my min(count of the_name, 8)
        log "minimumValue is " & minimumValue
        set the_short_name to items 1 thru minimumValue of the_name as string
        
        if exists folder the_short_name of this_folder then move this_file to folder the_short_name of this_folder
        
    end repeat
    
end tell

on min(x, y)
    if x ≤ y then
        return x
    else
        return y
    end if
end min

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Automator/Applescript to move files to folders

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.