Re: error code 2 when renaming file
Re: error code 2 when renaming file
- Subject: Re: error code 2 when renaming file
- From: Craig Knelsen <email@hidden>
- Date: Wed, 8 Dec 2004 10:08:54 -0600
The example script I gave was a simplification of what the real script
does. The actual script uses the current date and time to generate a
"unique" file name for the backup file. So, the real newName becomes
something like "something_20041208_095430.dat". True, the script wasn't
checking to see if this file already existed first although the chances
of it already existing were extremely small. Still, I guess I'll throw
that check in to be safe. As Emmanuel pointed out, I should have gotten
a dupFnErr (error -48) if the newName already existed.
I believe I have fixed the problem. I now do:
tell application "Finder"
update someFile
set the name of (someFile as alias) to newName
end tell
I sometimes run the script immediately after another application ends
which can change the file I'm trying to backup. It appears that the
Finder gets confused if a script tries to rename a file that was just
finished being used by another application. Perhaps a Finder caching
issue. I guess the script runs before the Finder has a chance to update
its cache.
On 7-Dec-04, at 6:15 PM, Emmanuel wrote:
At 12:05 PM -0800 07/12/04, Andrew Oliver wrote:
On 12/7/04 11:22 AM, "Craig Knelsen" <email@hidden> wrote:
I'm attempting to rename a file (backing it up before updating)
similar
to the following:
[snip]
It works most of the time but I sometimes get an error message "The
operation could not be completed (2)"
Ok, so why? The Finder might as well have told me "not today". How
can
I get more information on the root cause?
The commonest cause of failure for file renaming is an existing file
with
the target file name.
Wouldn't Craig get "a file with that name already exists" rather than
the cryptic message then?
_______________________________________________
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