appending to a file with open
Kenneth Brody
kenbrody at spamcop.net
Tue Jul 30 09:27:32 PDT 2013
On 7/30/2013 11:03 AM, tob at b-e-s-t.com wrote:
> I have a simple prc that writes the total records to a file.
>
> cat prc.left
> ::end:
> @wgt:::
> ::az(50,*)="/u/tob/ckinvct":
> ::aa=open(az,"rwt"):
> ::az=@qu<@ts:
> ::ab=writeline(aa,az):
> ::end:
>
> It works as expected BUT it does not append to the file but creates a new one on every run. I would like it to append to the file.
Well, by "creates a new one on every run", I assume you mean "overwrites the
file, starting at the beginning". Note that, if what you write is shorter
than what was already in the file, the "tail" of the file will still be there.
Currently, filePro doesn't have an "append" mode for OPEN(). However, you
can seek to the end of the file, just prior to the WRITELINE():
ab = seek(aa,"0","E") ; ab = writeline(aa,az)
This will cause the write to take place starting at the end of the file.
Note that there is a slight chance of a "race condition" here, should a
second process execute the SEEK() between the first process' SEEK() and
WRITELINE().
--
Kenneth Brody
More information about the Filepro-list
mailing list