Move file into folder with same name?

I need to merge files into folders once they have arrived at a holding folder.

set x to thisFile
set y to thisFolder
if first 5 letters of names match move x into y
move x to destination z and then delete x

We have an ‘on idle script’ waiting to invoke this as part of a larger script, so i’d rather avoid a folder action.
Any help would be great.

Hi and welcome!

see this link:
http://macscripter.net/viewtopic.php?id=34835

and this one: (a nice replacement for idle- if your dislike folder actions)
http://macscripter.net/viewtopic.php?id=20949

or save a stay-open app with:

prop tt:59 --repeat every hour

on idle
--parameters
return tt *60
end idle
--example:
tell application "Finder"
	--your path
	set targ_pt to folder of front window
	set get_file to item 1 of targ_pt
	--get names
	set nm to name of get_file
	set lg to (length of nm) div 2
	set sim_nm to (characters 1 thru lg of nm as text)
	--find similar folders
	set find_fl to list folder (targ_pt as text) without invisibles
	set targ_fl to items of find_fl whose name begins with sim_nm
	--move files
	if class of get_file is document file then move get_file to folder (targ_pt & targ_fl as text)
end tell

play around and have fun!

Thanks very much Joy, ill go away and have a good look at this information.