1. files...
- Posted by MiCkeY <mickeysc at ZAZ.COM.BR> Dec 23, 1999
- 317 views
- Last edited Dec 24, 1999
------=_NextPart_000_002A_01BF4D78.7343CA20 charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Is it possible to: 1=BA) delete a line (or more) of a file without copy all the file except = the lines I want to delete? 2=BA) read, ie, 10 lines of a file using gets() and after return to the = line 1 without have to close and open the file again? Thanks, Lu=EDs Fernando ------=_NextPart_000_002A_01BF4D78.7343CA20 charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META content=3D"text/html; charset=3Diso-8859-1" = http-equiv=3DContent-Type> <META content=3D"MSHTML 5.00.2614.3500" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT face=3DArial size=3D2>Is it possible to:</FONT></DIV> <DIV><FONT face=3DArial size=3D2></FONT> </DIV> <DIV><FONT face=3DArial size=3D2>1=BA) delete a line (or more) of a file = without copy=20 all the file except the lines I want to delete?</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>2=BA) read, ie, 10 lines of a file = using gets() and=20 after return to the line 1 without have to close and open the file=20 again?</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>Thanks,</FONT></DIV> <DIV><FONT face=3DArial size=3D2>Lu=EDs = ------=_NextPart_000_002A_01BF4D78.7343CA20--
2. Re: files...
- Posted by JJProg at CYBERBURY.NET Dec 24, 1999
- 318 views
>Is it possible to: >1º) delete a line (or more) of a file without copy all the file except the >lines I want to delete? >2º) read, ie, 10 lines of a file using gets() and after return to the line 1 >without have to close and open the file again? >Thanks, >Luís Fernando To answer your second question: You can use seek in file.e to return to the beginning of the file without closing it and opening it again. As far as I know, there is no really simple way to do what you are asking in your first question. If you know the position in the file of where you want to start deleting and where you want to end, you can use seek and only copy the second half of the file. If the file you are writing can have extra whitespace - an INI file, for example, you could replace the line you are trying to delete with spaces or newline characters. Jeffrey Fielding JJProg at cyberbury.net http://members.tripod.com/~JJProg/
3. Re: files...
- Posted by Irv Mullins <irv at ELLIJAY.COM> Dec 27, 1999
- 319 views
On Thu, 23 Dec 1999, MiCkey wrote: > >%_Is it possible to: > > 1º) delete a line (or more) of a file without copy all the file except the > lines I want to delete? > > 2º) read, ie, 10 lines of a file using gets() and after return to the line 1 > without have to close and open the file again? > > Thanks, > Luís Fernando If you mean a text file containing random-length lines, the only way is to read the data in, remove the lines, and write the data back to the file. This is true of any language that can write "text" files. You can do this one line at a time, reading the old file and writing to a new file. If the file is not larger than the memory in your computer, then you can read the entire file into a sequence, remove lines from the sequence, and write the entire file back to disk. This is much faster than the one-line at a time method. sequence s object line integer fn s = {} fn = open("dbase.html","r") -- read mode while 1 do line = gets(fn) if atom(line) then exit -- EOF else s = append(s,line) end if end while close(fn) -- s will contain the lines: s[1] is line 1, s[20] is line 20..... -- do your deletions here, the write the lines back using a -- loop: fn = open("dbase.html","w") -- write mode for i = 1 to length(s) do puts(fn,s[i]]) end for close(fn) Regards, Irv