script to get rid of "bad" characters in filenames

Hi, I’m struggling trying to write a script that will get rid of bad characters in filenames, such as " ", “/”, "" and replace them with underscore. So a filename named "US/Dakota ad file .pdf would be something like “US_Dakota_ad_file__.pdf”
I have hundreds of files to process. Thanks guys.

Hi,

take a look at this thread

OK got this working, slow but working

on open item_list
set char_list to {" ", “/”}
set good_char to {“a”, “b”, “c”, “d”, “e”, “f”, “g”, “h”, “i”, “j”, “k”, “l”, “m”, “n”, “o”, “p”, “q”, “r”, “s”, “t”, “u”, “v”, “w”, “x”, “y”, “z”, “.”, “_”, “+”, “-”, “0”, “1”, “2”, “3”, “4”, “5”, “6”, “7”, “8”, “9”}
repeat with this_item in item_list
set a to 1
set newname to “”

	tell application "Finder"
		activate
		
		set my_folder to (get container of file this_item)
		set my_filename to get the name of this_item
		set char to get every character of my_filename as list
		
		repeat (count every item in char) times
			set char_let to (get item a of char) as string
			if char_let is return or char_let is not in good_char then set char_let to ""
			
			if char_let is " " then set char_let to "_"
			if char_let is not in char_list then set newname to newname & char_let
			
			set a to a + 1
		end repeat
		set the name of file my_filename of my_folder to newname
	end tell
end repeat

end open

veeeeery slooooooow