Reading/Deleting Last Line Of File

Alex Tweedly alex at
Fri Feb 12 09:39:15 EST 2010

Richard Gaskin wrote:
> That looks similar to what I posted here on the 9th:
>    open file tFile for update
>    seek relative -1000 in file tFile
>    repeat
>       read from file tFile until cr
>       if it is not empty then
>          put it after tBuffer
>       else
>          delete last line of tBuffer
>          write tBuffer to file tFile
>       end if
>    end repeat
>    close file tFile
> Does that not do what you need?
No, it doesn't. If a file is opened for 'update' then any write to the 
file simply overwrites any existing characters at the appropriates 
position(s), and leaves everything following that unchanged. There is no 
EOF implied by a write in update mode. There is an EOF inserted after a 
write if the file is opened in 'append' mode - but then you cannot read 
from it.

(Actually, there is another additional reason - each time you do a 
'read' that updates the file pointer, so the subsequent write would 
begin at the file position immediately *after* the last read, not where 
the read had been done from; you would have needed another seek before 
write  (or do a 'write at x') to have a chance, but you'd still need Rev 
to provide access to truncate() after your write.)

-- Alex.

More information about the Use-livecode mailing list