Re: When is a file open but not open?
Re: When is a file open but not open?
- Subject: Re: When is a file open but not open?
- From: deivy petrescu <email@hidden>
- Date: Fri, 5 Aug 2005 17:20:50 -0400
On Aug 5, 2005, at 13:42, Emmanuel wrote:
At 12:08 PM -0400 8/5/05, Grimm, Kenneth wrote:
So when would I use just "write" in place of the "open for
access/write/close for access" dance?
Note that when you just "write" you write to the beginning of the
file, but you do not shorten the file: if you write "R" to a file
which stores "Bush" you get "Rush".
Is one safer? Provides file locking? All my books suggest the
dance, not
just the "write"... can you explain further why one and not the
other, or do
both have their place in certain instances?
There are two instances that I know where you want to open the file
with write permission before writing.
1 - you need sequential access: for instance, you want to write
several things one after the other:
write "hello"
write " "
write "world"
I disagree with you here Emmanuel.
When you write you can write wherever you want. You have to let the
script know where you want to write to.
So "write to file starting at (you fill this)" works the same way
whether opened for access or not.
You can try.
If you do that the file being not open, as I told above you write
and rewrite the beginning of the file only.
2 - you need to be sure that no-one is also writing to the file:
open with write permission does lock the file - actually I think
it's the OS' genuine mechanism to lock whatever resource might be
accessed by several clients.
Here, I really do not know and yield to Emmanuel's knowledge. There
are ways around this. You could lock and unlock the file as needed.
To read the file it is easier, as Emmanuel thought me, to open for
access, but one can, with much more code do without it.
However, open for access always burns me. I always have to quit and
restart Smile or Script Editor.
Emmanuel
Deivy
_______________________________________________
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