Finding and replacing multiple characters
Finding and replacing multiple characters
- Subject: Finding and replacing multiple characters
- From: Yannick Brodeur <email@hidden>
- Date: Tue, 8 Jul 2003 19:04:56 -0400
I need a script that would edit the names of files and folders in a
chosen directory. The following characters / \ : * ? " < > needs to be
replaced by an underscore.
I found this script, wich works great but only allows to change a
single character into an underscore.
Code:
on change_item_names(source_folder, search_parameter, search_string,
replacement_string)
tell application "Finder"
try
-- Get the names to be changed
if search_parameter contains "Folder" then
set target_names to (name of folders of source_folder whose
name contains search_string) as list
else if search_parameter contains "File" then
set target_names to (name of files of source_folder whose
name contains search_string) as list
else
set target_names to (name of items of source_folder whose
name contains search_string) as list
end if
-- Change the names of the items with those names
set astid to AppleScript's text item delimiters
repeat with i from 1 to (count target_names)
set this_name to item i of target_names
set AppleScript's text item delimiters to search_string
set text_items to this_name's text items
set AppleScript's text item delimiters to replacement_string
set name of item this_name of source_folder to text_items
as string
end repeat
set AppleScript's text item delimiters to astid
end try
-- Recurse through the subfolders
set the_folders to source_folder's folders
repeat with this_folder in the_folders
my change_item_names(this_folder, search_parameter,
search_string, replacement_string)
end repeat
end tell
end change_item_names
change_item_names(choose folder, "Both", "/", " _")
What are the changes I would need to make so the script be able to
replace more than one character ?
Can anyone help me on this one?
Thank you in advance
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.