Re: Renaming a copied file with Finder
Re: Renaming a copied file with Finder
- Subject: Re: Renaming a copied file with Finder
- From: Christopher Nebel <email@hidden>
- Date: Mon, 9 Oct 2006 09:27:02 -0700
On Oct 9, 2006, at 7:29 AM, Yvan KOENIG wrote:
Best as I can tell, you can't do it directly. Here is my work
around.
set file_to_copy to (choose file)
set target_folder to (choose folder)
tell application "Finder"
try
duplicate file_to_copy to target_folder without replacing
on error msg number num
if num is -15267 then
set new_name to display dialog msg & " Please choose another
name for the copy." default answer (name of file_to_copy) & " copy"
set new_file to duplicate file_to_copy
move new_file to target_folder
else
display dialog msg
end if
end try
end tell
and what if (name of file_to_copy) & " copy" already exists ? ;-)
It's irrelevant, because that block will never be executed. The
Finder's "duplicate" command (without replacing) will rename the new
file as necessary ("foo copy n") to avoid a collision. ("How do I get
a reference to the new file if I don't know its name?", you ask?
"Duplicate" returns a reference to the new file as its result.)
--Chris Nebel
AppleScript Engineering
_______________________________________________
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