trying to move files based on file names...

ok, so i feel like this should be an easy thing to accomplish, but sadly, i can’t seem to get it. here’s what i got…i have an automator app that will take a file that has been scanned in (pdf) and rename it to the name in a field in one of my filemaker databases. got that working. now, depending on the name of the file, i need this applescript to move that file to the correct folder. for instance…if the file name starts with “P”, then i need it to move to ‘folder 1’. if it starts with 'L", it needs to move to ‘folder 2’…and so on. this is what i’ve got, but it doesn’t work. can someone point me in the right direction?


on run {input, parameters}
	
	set FileName to input as text
	
	tell application "Finder"
	        if name of FileName starts with "P" then
			move file FileName to folder "Drive:Folder:Folder1"
			
	        else if name of FileName starts with "8" then
			move file FileName to folder "Drive:Folder:Folder2"
			
	        else if name of FileName starts with "L" then
			move file FileName to folder "Drive:Folder:Folder3"
			
		else if name of FileName starts with "T" then
			move file FileName to folder "Drive:Folder:Folder4"
			
		end if
	end tell
	return input
end run

:confused:

Model: iMac
Browser: Safari 533.17.8
Operating System: Mac OS X (10.6)

Hi,

I don’t know what class input is (I guess list of alias), but maybe it’s sufficient to add the keyword file


.
 if name of file FileName starts with "P" then
.

If input is a POSIX path try


on run {input, parameters}
	
	set FileName to input as text
	set FileNameAlias to POSIX file FileName as alias
	tell application "Finder"
		if name of FileNameAlias starts with "P" then
			move FileNameAlias to folder "Drive:Folder:Folder1"
			
		else if name of FileNameAlias starts with "8" then
			move FileNameAlias to folder "Drive:Folder:Folder2"
			
		else if name of FileNameAlias starts with "L" then
			move FileNameAlias to folder "Drive:Folder:Folder3"
			
		else if name of FileNameAlias starts with "T" then
			move FileNameAlias to folder "Drive:Folder:Folder4"
			
		end if
	end tell
	return input
end run

if you want to process more than one file the routine probably fails, because input is usually a list

no, the input is the file that is being passed on in the automator action. it’s being fed the pdf file after being renamed. i played around with it a little more and i’ve gotten it to not error out, but it’s still not moving the file either…this is the only change i made…



		if character 1 of FileName is "P" then

a “file” could be an alias, a file specifier, a HFS path or a POSIX path.
Each case must be treated differently.

ahhh. got it. it was throwing the entire file path into the parameter, so i was actually pulling the first letter of the drive name, not the file name. fixed. working. thanks!