Re: Update file
- Posted by Ad Rienks <Ad_Rienks at COMPUSERVE.COM> Sep 22, 1997
- 864 views
Robert Craig wrote: >You can use the functions where() and seek() to position >yourself in the file. Each open file has a "current position" >based on reads and writes to the file. You can find out the >current position using where(). You can set the current position >using seek(). >Here's a simple example. It opens a file using "ub" - binary >update mode. I think it's better to use binary mode than text >mode, with seek() and where(), because in text mode you don't >read \r characters, but they are still counted as far as the >seek position is concerned, so things might get confusing. The >example records the starting position of each line in the >"test.dat" file. It is then able to pick a line at random and >replace it with a string of X's. = Hello Rob, =46rom your example I deduce that in update mode a line can be replaced, = but only if the new line is exactly the same length as the old one. Is this t= he only way to work in update mode? Is it for instance not possible to inser= t a line in between other lines? I know it is possible to append lines at the end of a file, but for that purpose you also have the append mode. Personally when I update a file, I first read them into (a) sequence(s), close the file and after updating I open the file again for writing. Mayb= e this is more time-consuming, but when time is not that important, at the beginning and end of a program..... Sincerely, Ad Rienks email Ad_Rienks at compuserve.com writing at 19:08 , = on maandag 22 september 1997 Using EMail Assist for WinCIM