Re: Duplicating a file to a specific name
Re: Duplicating a file to a specific name
- Subject: Re: Duplicating a file to a specific name
- From: Andy Wylie <email@hidden>
- Date: Sat, 28 Dec 2002 10:52:40 +1300
on Thu, 26 Dec 2002 23:08:45 -0700 David Crowe wrote:
>
The Finder "duplicate" command can copy a file to a specific folder.
>
>
Is there any convenient way to set the filename as part of this operation?
>
>
I could do the duplicate and then change the name, but then I have
>
the situation when a file with the same name exists in the
>
destination folder.
>
deal with it :)...
tell application "Finder"
set {folName, newFolName, cnt} to {"Test", "Test", 0}
set |exists| to (get exists of folder named folName of desktop)
repeat until |exists| = false
set cnt to cnt + 1
set newFolName to folName & cnt
set |exists| to (get exists of folder named newFolName of desktop)
end repeat
set newFolder to (make new folder at desktop with properties
{name:newFolName})
end tell
--------------or...
to testName(x)
try
x as alias
return true
on error m number n
if n is in {-35, -37, -43, -120, -1700} then return false
error m number n
end try
end testName
-- -35 is "Disk wasn't found", -37: "Bad name for file",
-- -43: "File wasn't found", -120: "Folder wasn't found",
-- -1700: "Can't make [file specification] into an alias"
set cnt to 0
set filename to choose file
set new_Name to filename
repeat until testName(new_Name) = false
set cnt to cnt + 1
set new_Name to filename & cnt
end repeat
new_Name
_____________________________ Andy
_______________________________________________
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.