Leopard broke my script...

I have a relatively simple droplet that takes the PDF files you drop and does the following: creates a folder by the same name in the destination of your choosing -or- if the folder exists puts the PDF file in that folder (with replacing). The script below worked fine on 10.4, but for some reason returns an error on 10.5 (The operation could not be completed because there is already an item with that name.). I’m not a scripting expert and could use some help identifying what needs to change to get this to work on 10.5.

– AppleScript droplet. Drag and drop your pdf files onto this script
– saved as an application.
on open (systemItems)

set deskpath to path to desktop as string
-- Have user select folder for output
tell me to activate
try
	choose folder with prompt "Choose location for folder output:"
on error
	deskpath
end try
set outfolder to result as string


set astids to AppleScript's text item delimiters
try
	
	set targetPath to outfolder as string
	
	--   Coerce the alias list to path-strings 
	-- 
	set AppleScript's text item delimiters to "/:"
	set systemPaths to (systemItems as string)'s text items
	
	--   The names of the folders of the targetFolder 
	-- 
	tell application "Finder" to set folderNames to ¬
		name of every folder of folder (targetPath)
	
	set AppleScript's text item delimiters to ":"
	
	repeat with i from 1 to systemItems's length
		
		set pathString to systemPaths's item i
		
		if (pathString ends with ".pdf") then -- filter the pdfs from drag/drop 
			
			set pathString to pathString's ¬
				text from text item -1 to character -5 -- remove ext. 
			
			if (folderNames contains pathString) then -- folder exists 
				
				--   "move" can be changed to "duplicate": 
				-- 
				tell application "Finder" to ¬
					move file ((systemItems's item i) as string) to ¬
						folder (pathString) of folder (targetPath) ¬
						with replacing
				-- 
				--   with replacing means that if the script is run 2 or 
				--   more times, and a drag/dropped pdf file has the same 
				--   name as a previous one, then the one just dropped 
				--   replaces the existing one. 
				
			else -- create the folder 
				
				tell application "Finder"
					
					make new (folder) at (folder targetPath) ¬
						with properties {name:pathString}
					
					--   "duplicate" can be changed to "move": 
					-- 
					move file ((systemItems's item i) as string) to ¬
						folder (pathString) of folder (targetPath) ¬
						with replacing
					
				end tell
			end if
		end if
	end repeat
	
	set AppleScript's text item delimiters to astids
on error e number n from f to t partial result p
	set AppleScript's text item delimiters to astids
	error e number n from f to t partial result p
end try

end open

Hi,

try to replace with replacing with replacing yes

this is a simpler version of your script


--   AppleScript droplet. Drag and drop your pdf files onto this script 
--   saved as an application. 
on open systemItems
	set outfolder to path to desktop
	-- Have user select folder for output
	tell me to activate
	try
		set outfolder to (choose folder with prompt "Choose location for folder output:")
	end try
	
	repeat with oneItem in systemItems
		tell application "Finder" to set fileName to name of oneItem
		if fileName ends with ".pdf" then
			set folderName to text 1 thru -5 of fileName
			tell application "Finder"
				if not (folder folderName of outfolder exists) then
					make new folder at outfolder with properties {name:folderName}
				end if
				move oneItem to folder folderName of outfolder replacing yes
			end tell
		end if
	end repeat
end open