Rename pdf files of folder with dialog box.

Hi, first post. I have a bit of a pickle here. First off, I have been racking my brains over this. I had this working last week and went to make a backup of my master image through deploystudio and everything crashed hard. Lost my images, lost my master image due to faulty hardware.
Hardware
iMac i5 Lion OS

So here is where I am. I Print PDF’s through CUPS_PDF to a folder and a folder event takes over. When the file drops in it prompts to “Please Name Your Print Job”. It would get all files of a folder (which should only ever be one file) and rename the file with the answer provided by the dialogue box.

this section all works and has been rewritten.
After that the Automator folder event continues to changes the current printer to a PS printer that will send the print job to a printqueue on a server. once the job is printed it changes the current printer back to CUPS-PDF printer and finally deletes the pdf file from the folder event folder, which is why there should never be more than one file in the folder.

The chunk of applescript that is broken is the renaming of “all files” of that folder. There was a piece in there for list to iterate through the files. Any and all help would be appreciated.

Some of the script below has been found on google and this site. I appreciate the wealth of knowledge that is here. I unfortunately can not find my answer in the forums.

repeat
	set question to display dialog ("Please Name Your Print Job.") default answer ""
	set the_answer to text returned of the result
	if the_answer is not equal to "" then exit repeat
end repeat

tell application "Finder"
	try
		set the_folder to ("Macintosh HD:private:var:spool:cups-pdf:librarypatron" as string)
		--display dialog fileAlias
		tell application "Finder"
			set fileAlias to name of files in folder the_folder
			display dialog fileAlias
			
			--set fileAlias to (choose file)
			--set filePath to fileAlias as text
			--set TID to AppleScript's text item delimiters
			--set AppleScript's text item delimiters to ":"
			set fileName to fileAlias
			display dialog fileName
			set AppleScript's text item delimiters to "."
			set fileNamePart1 to text item 1 of fileName
			set fileNamePart2 to text item 2 of fileName
			set fileName to the_Aswer & "." & fileNamePart2
			set AppleScript's text item delimiters to TID
			display dialog fileName
			set name of fileAlias to fileName
		end tell
		--end repeat
	end try
end tell

Model: imac
AppleScript: 2.2
Browser: Firefox 7.0.1
Operating System: Mac OS X (10.7)

Hi. If there is always 1 file, then you really don’t need to do much other than change the name. I cut out the nonessential parts.


tell application "Finder"
	tell  (folder "Macintosh HD:private:var:spool:cups-pdf:librarypatron")'s file 1 to set name to ¬
		((display dialog "Please Name Your Print Job." default answer "")'s text returned & "." & its name extension)
end tell

Thank you so much. The simplicity of that is amazing. Thanks again.