Re: Replace names of files in different folders
Re: Replace names of files in different folders
- Subject: Re: Replace names of files in different folders
- From: has <email@hidden>
- Date: Wed, 12 Apr 2006 14:01:37 +0100
Jan Bultereys wrote:
>Hi does anyone have a better solution:
Not tested but should work:
set jobs_list to {¬
{folder_name:"BELGIUM_NL", name_changes:{{"OG1H", "GW1W"}, {"OG2H", "GW2W"}}}, ¬
{folder_name:"BELGIUM_FR", name_changes:{{"OG1H", "GF1F"}, {"OG2H", "GF2F"}}} ¬
}
repeat with job_ref in jobs_list
set source_folder to choose folder with prompt folder_name of job_ref
rename_items_in_folder(source_folder, name_changes of job_ref)
end repeat
to rename_items_in_folder(the_folder, changes_list)
tell application "Finder"
--rename items in this folder
repeat with item_ref in (get items of the_folder)
set item_name to name of item_ref
repeat with change_ref in changes_list
set {search_string, replace_string} to change_ref
if item_name contains search_string then
set name of item_ref to ¬
my find_and_replace(item_name, search_string, replace_string)
exit repeat
end if
end repeat
end repeat
--recursively rename items in any sub-folders
repeat with sub_folder_ref in (get folders of the_folder)
my rename_items_in_folder(sub_folder_ref, search_string, replace_string)
end repeat
end tell
end rename_items_in_folder
to find_and_replace(the_string, search_string, replace_string)
set AppleScript's text item delimiters to search_string
set temp_list to every text item of the_string
set AppleScript's text item delimiters to replace_string
set the_string to the temp_list as string
set AppleScript's text item delimiters to ""
return the_string
end find_and_replace
HTH
has
--
http://freespace.virgin.net/hamish.sanderson/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden