Problem with Rename Droplet

I am having a problem with my code below. I need to be able to drop a selection of file and the droplet and have it take all of the “.” out of the file and replace with “_” and then add the extinision to the end of “.qxd”. It would be nice if it would accept file and folders, but I only have to have it work with files. Thank you in advance.


on open files2rename
tell application "Finder"
   set FolderRef to FolderOfFiles as string
   set FolderContents to files of folder FolderRefend tell

repeat with TheFile in FolderContents
   
   set ThisFilesName to name of TheFile as string
   
   set ThisFilesName to replace_chars(ThisFilesName, ".", "_") 
   
   set name of TheFile to ThisFilesName & ".qxd"
   
end repeat

display dialog "All filenames have been renamed"


on replace_chars(this_text, search_string, replacement_string)
   set AppleScript's text item delimiters to the search_string
   set the item_list to every text item of this_text
   set AppleScript's text item delimiters to the replacement_string
   set this_text to the item_list as string
   set AppleScript's text item delimiters to ""
   return this_text
end replace_chars
end open

You almost had it!


on open MasterFolder
	tell application "Finder"
		--Reference to a folder
		set FolderRef to MasterFolder as string
		--Gets contents of folder ready for processing
		set FolderContents to items of folder FolderRef
	end tell
	
	repeat with TheItem in FolderContents --Begins processing master folder
		
		set ThisFilesName to name of TheItem as string
		
		set ThisFilesName to replace_chars(ThisFilesName, ".", "_")
		
		set name of TheItem to ThisFilesName & ".qxd"
		
	end repeat
	display dialog "All filenames have been renamed"
end open



on replace_chars(this_text, search_string, replacement_string)
	set AppleScript's text item delimiters to the search_string
	set the item_list to every text item of this_text
	set AppleScript's text item delimiters to the replacement_string
	set this_text to the item_list as string
	set AppleScript's text item delimiters to ""
	return this_text
end replace_chars

SC