Repeating

Hi
I’m trying to write a script that shifts files into different folders based on their size;

on open the_files
set pathname to the_files as alias
tell application “Finder”
set theresult to (size of the pathname as integer)
if theresult is greater than 7000000 then
move pathname to folder “Big” of folder “Desktop” of folder ¬
“myfolder” of folder “Users” of the startup disk
else
move pathname to folder “Small” of folder “Desktop” of folder ¬
“myfolder” of folder “Users” of the startup disk
end if
end tell
end open

the above works fine if I drop one file at a time but gives an error if I try to do multiple files. Ultimately, it’ll be set up as an attached script to a watched folder. I’m assuming that I need to stick some sort of repeat into the script but I’m not sure on how to do it exactly - don’t worry about my vague file calculation sizes as it doesn’t have to be terribly exact.
Any help appreciated!!
Thanks

Hi :slight_smile:
Try this syntax :

on open the_files
	tell application "Finder"
		repeat with AFile in the_files --Loop with each item in variable "the_files"
			set pathname to AFile as alias
			set theresult to (size of the pathname as integer)
			if theresult is greater than 7000000 then
				move pathname to folder "Big" of folder "Desktop" of folder ¬
					"myfolder" of folder "Users" of the startup disk
			else
				move pathname to folder "Small" of folder "Desktop" of folder ¬
					"myfolder" of folder "Users" of the startup disk
			end if
		end repeat
	end tell
end open

:slight_smile:

works perfectly - thanks for your help!!