Re: Closing a file you left open (error -49)
Re: Closing a file you left open (error -49)
- Subject: Re: Closing a file you left open (error -49)
- From: "Stockly, Ed" <email@hidden>
- Date: Tue, 19 Apr 2011 13:27:31 -0500
- Acceptlanguage: en-US
- Thread-topic: Closing a file you left open (error -49)
On 4/19/11 11:15 AM, "Ruffin Bailey" <email@hidden> wrote:
> Is there a way to check for an open file and then force it closed? I've also
tried closing the file in the start of the script by building another reference
(and just ignoring the close if there's an error; say, the file's > not open),
but no luck there either.
Below is the handler I use for opening and writing.
> Further, is there an easy way to get rid of the open file and start over?
I've tried deleting from the command line without luck; my script still sees
the file open the next time I try.
I think you need to close the file before you can delete it. You could use
Finder to move it to the trash, rather than the shell to delete in place.
Either way, using the handler below eliminates this issue as well.
HTH,
ES
Set myFile to choose file as text
Set myText to "Foo"
OpenWriteClose(myFile, myText)
on OpenWriteClose(myFile, myText)
try
set openFile to (open for access file myFile with write permission)
on error errText
set errText to errText as text
close access file myFile
set openFile to (open for access file myFile with write permission)
end try
set eof of openFile to 1
write myText to openFile
close access openFile
end OpenWriteClose
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden