Re: Close Access
Re: Close Access
- Subject: Re: Close Access
- From: Shane Stanley <email@hidden>
- Date: Sun, 27 Jan 2002 21:32:17 +1100
On 27/1/02 7:53 PM +1000, John McAdams, email@hidden, wrote:
>
I was just reading through the "read" section of "AppleScript in a
>
Nutshell." On p.462 Mr Perry suggests using "close access" after
>
reading. However when I try this (in X, haven't tried it in 9), I get an
>
error that the file isn't open. Now, all psyched up at the prospect of
>
finding a bug, I post the observation.
>
>
To wit--on p.463 Mr Perry suggests using "read theFile before return"
>
within a "repeat number_of_file_lines times" statement to "neatly read
>
the file line by line." My attempts neatly read the entire file
>
"number_of_file_lines" times. Bug? Or old news?
I don't have the book, but you only use 'close access" if you first used
"open for access" to open the file. If you use the read command without the
open for access command, the single command does the open, read, and close
for you.
The advantage of using open for access is that statements like "read theFile
before return" can be used, and the system will automatically keep track of
where you're up to. Plus, the read command alone has been known to fail in
some situations.
The normal method is something like this:
set fileRef to open for access file filePath
set theDat to read fileRef -- or whatever
close access fileRef
--
Shane Stanley, email@hidden
References: | |
| >Close Access (From: John McAdams <email@hidden>) |