File - read from EOF

hh hh at
Sun May 28 16:29:33 EDT 2017

[This certainly depends upon how you read 'sections'.
If one uses a separator and search backwards then you'll get empty
before the first if at start of file.]

When testing this 'ineffective' way (because of searching backwards)
I found a better method:

Say your separator is for example c0=numToChar(0) and assume you
would like to have the sections as they are (not the chars reversed).

Then you could read once thru the file (don't read in the full file)
and collect the lengths of your sections by "read from file until c0"
in an array.
Then you know the number and lengths of your sections and you could
use "repeat for each" to read in the sections you want and in the
order you want. (Using negative start numbers may be comfortable here.)

This works here and LC is very fast with this.

> JB wrote:
> That did not work for me.  When I read the data is
> put into it so I was putting empty into it after the
> read to make sure it was clear.
> I tried not putting empty into it and used,
> repeat until it = empty
> but apparently it never became empty.
> > hh wrote:
> >> JB wrote:
> >> ... I want to read in sections from the EOF and
> >> stop at the beginning of the file instead reading
> >> from the start to EOF.
> >> I have no problems opening, reading and
> >> closing files or reading in sections.
> >> Does anyone know the easiest way to determine
> >> when I reach the start of the file similar to
> >> using EOF to stop reading at the end of the file?
> > 
> > As you know how to read in sections:
> > Simply read one section after the next one until
> > it is empty.

More information about the use-livecode mailing list