Renaming PDFs on my desktop and then moving them

I am writing this script that renames PDFs on my desktop, and then moves them to the appropriate folder.

I have got the renaming part done. But for the life of me, I can’t figure out how to get the move part of the script to work.

Anyway, here’s the code:

-- Step One: Get a list of MWJ issues files on the desktop (as aliases) 
tell application "Finder" to tell (files whose name begins with "MWJ_") to try
	set fileList to it as alias list
on error
	set fileList to it as alias as list
end try

-- Step Two: Check and see if there are  *any * issues of MWJ in the desktop folder
if (count fileList) is 0 then display dialog "There are no issues of MWJ on the desktop." buttons {"Cancel"} default button 1

-- Step Three:  Take the list that we created in the first step, and manipulate the name, and move it to the appropriate folder
repeat with i from 1 to (count fileList)
	set currentFile to (item i of fileList as alias)
	set currentInfo to info for currentFile
	set currentName to the name of currentInfo
		set currentYear to characters 5 through 8 of currentName as string
		set currentMonth to (characters 9 through 10 of currentName) as string
		set currentDay to (characters 11 through 12 of currentName) as string
		set newName to ("MWJ " & currentMonth & "-" & currentDay & ".pdf") as text
		tell application "Finder"
			set the name of currentFile to newName
		end tell
	on error theErr
		display dialog "Something went wrong. Error # " & theErr buttons {"Cancel"} default button 1
	end try
		set partPath to "Dylan:Users:tom:Documents:MWJ:"
		set newPath to partPath & currentYear as string
		tell application "Finder"
			move currentFile to newPath
		end tell
	on error errTwo
		display dialog errTwo buttons {"Cancel"} default button 1
	end try
end repeat

I think the problem is with the newPath variable – it’s the wrong class. What should I be doing?

Thanks for any and all help,
Tom McKenna (a newbie who just finished AS: The Definitive Guide)

Hi Tom,

What happens if you change ‘move currentFile to newPath’ to this ‘move currentFile to folder newPath’ ?

– Rob

That fixed the problem!

I really appreciate the help! If I can indulge you for a minute, why did this code work?

set partPath to "Dylan:Users:tom:Documents:MWJ:"
set restPath to "2004"
set fullPath to partPath & restPath
set fullPath to fullPath as string

set theFile to alias "Dylan:Users:tom:Documents:MWJ:2004:test.rtf"

tell application "Finder"
	move theFile to fullPath
end tell

This code worked fine. Why didn’t it error out as well?

Thanks again,

I can’t explain why your last example worked when the first one failed. It seems to me that both should have failed.

– Rob