I know this shouldn’t be too hard but I’ve hit a road block. I have a folder with many, many files inside, 2000 or so. I’d like to break these up into groups of 100 and put in new folders, the order doesn’t matter. So basically the script would take the contents of a folder and create new folders and place 100 of the items as needed. I can only get it to work if I create the new folders manually beforehand, which kind of ruins the point. Any ideas?
Easy peasy:
set items_per_subfolder to 100
set subfolder_prefix to "subfolder "
tell application "Finder"
activate
set the_folder to (choose folder) as alias
set {i, j, the_contents} to {1, 1, (items of the_folder)}
set new_folder to make new folder at the_folder with properties {name:(subfolder_prefix & (j as string))}
repeat with this_item in the_contents
if i > items_per_subfolder then
set {i, j} to {1, (j + 1)}
set new_folder to make new folder at the_folder with properties {name:(subfolder_prefix & (j as string))}
end if
move this_item to new_folder
set i to i + 1
end repeat
beep
display dialog (((count of the_contents) as string) & " items split into " & (j as string) & " subfolders.") buttons {"OK"} default button 1 with icon 1 giving up after 10
end tell
Jon
Jon,
as always, Thanks!