Re: Read File Problems
Re: Read File Problems
- Subject: Re: Read File Problems
- From: Richard 23 <email@hidden>
- Date: Tue, 20 Mar 2001 08:38:53 -0800
>
>On 20/3/01 2:27 PM +1000, Paul Berkowitz, email@hidden, wrote:
>
>
>
>> So -- what's the point of the 'write permission' parameter, if the _only_
>
>> thing you need to open for access for is to write to the file?
>
>Opening the file first has considerable advantages if you're not reading the
>
>whole thing in at once -- it's quicker, and it automatically keeps track of
>
>where you're up to.
>
My own investigation into this sort of thing last year suggests that a
>
"simple read" - like a read by file specification after opening for
>
access - first checks whether there's an open-file reference for that
>
file. If there is, it uses it; if not, it opens the file itself. The
>
reference for a freshly opened file has its file pointer set for the
>
beginning of the file, but a reference that has already been read or
>
written to will have the pointer set somewhere else. This means that if
>
the file is already open - either because it's in use or because some
>
previous error has prevented it from closing - a simple read has a good
>
chance of not getting the expected results. You can get round this using
>
the 'from' and 'to' parameters, but then you screw up the file pointer
>
for whatever process opened the file in the first place - which may not
>
be the current script.
>
>
NG
Although faded, yellowing and in need of an update, the Scripting
Additions
Guide is pretty specific about this (and concurs with Nigel's assessment):
If you specify a reference to a file or an alias, the Read command
attempts to match the reference with a file previously opened with
the Open for Access command. If a match is found, it simply reads
the specified data. If no match is found, the Read command opens
the file, reads the specified data, then closes the file. The file
mark for a file opened in this fashion is always at the beginning
of the file.
If you specify a file reference number previously obtained with
the Open for Access command, the Read command reads the specified
data immediately.
I looked through my Additions folder and couldn't find any of these files
the guide says are located in the Extensions folder in the System Folder:
(In fact I couldn't find the folder anywhere in my Extensions Folder...
something must be wrong with my System!)
Beep, Choose Application, Choose File, Choose Folder, Current Date,
Display Dialog, File Commands, Load Script, New File, Numerics,
Read/Write Commands, Run Script, Scripting Components, Store Script,
String Commands, Time to GMT
OK, no helpful emails...I'm kidding. It's perhaps time for an update!
R23