Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

automator or script to create folders based on file names and move files

Hello,


i had a clunky script set up where i could select a list of files and they would be moved to existing, or new folders based on their filenames, but two Macs and 3 versions of OSX later i seem to have lost it.


i deal with image and video files which i organize by year, month, and date.

"real" camera downloads are dealt with daily and not an issue, but every month i do a phone dump, so i could have a few hundred files to organize.


file names could be the following:


2019_11_23_5432.jpg

2020_01_30_2345.jpg

2020_02_02_2765.jpg

2020_02_02_2766.jpg

2020_02_03_2795.jpg


at a minimum i'd like each file from the same date put into a folder named for that date.


2019_11_23

2020_01_30

2020_02_02

2020_02_03


multiple files (like 2020_02_02... above) would go into the same folder obviously.


previously i had a script cobbled together where i could select all, run the script, and sometimes it would choke if there were multiple files on the same date, sometimes it would sail through perfectly, i could never figure out why sometimes it stopped early, usually manually moving one file and then re-running the script worked.

MacBook Pro 13", macOS 10.14

Posted on Mar 5, 2020 9:24 AM

Reply
Question marked as Best reply

Posted on Mar 5, 2020 10:29 AM

Use code such as:


tell application "Finder"

set the_folder to folder "Desktop" of home

repeat with this_file in (get files of the_folder)

set the_name to items 1 thru 10 of (get name of (this_file as alias)) as string

try

make new folder in the_folder with properties {name:the_name}

end try

move this_file to folder the_name of the_folder

end repeat

end tell


(179250)

Similar questions

2 replies
Question marked as Best reply

Mar 5, 2020 10:29 AM in response to JohnOBPhoto

Use code such as:


tell application "Finder"

set the_folder to folder "Desktop" of home

repeat with this_file in (get files of the_folder)

set the_name to items 1 thru 10 of (get name of (this_file as alias)) as string

try

make new folder in the_folder with properties {name:the_name}

end try

move this_file to folder the_name of the_folder

end repeat

end tell


(179250)

automator or script to create folders based on file names and move files

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