Home > Archive > Programming with dBASE > November 2006 > Insert text









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Insert text
Bruce Mercer

2006-11-10, 12:12 am

Hi all,

Is it possible to insert a line of text into the top of a
text file. I have tried using the file class, but puts over
writes the first line.

Any Ideas, besides building the entire text file.

Thanks
Bruce


bigMike

2006-11-10, 7:16 pm

How about something like this:

a = original_text
b = new_text
save b+a to text file

I'm sure there are other ways, too. This is just a quickie answer.

bigMike


"Bruce Mercer" < brucewm53remove@yaho
o.com> wrote in message
news:SOOV4WHBHHA.2124@news-server...
> Hi all,
>
> Is it possible to insert a line of text into the top of a
> text file. I have tried using the file class, but puts over
> writes the first line.
>
> Any Ideas, besides building the entire text file.
>
> Thanks
> Bruce
>



Bruce Mercer

2006-11-10, 7:16 pm

Thanks Mike,

Problem is.... a = 5mb 30,000 line CSV file.

TIA
Bruce


"bigMike" <bigmikeaa@hotmail.com> wrote in message
news:F1HOJLNBHHA.2100@news-server...
> How about something like this:
>
> a = original_text
> b = new_text
> save b+a to text file
>
> I'm sure there are other ways, too. This is just a quickie answer.
>
> bigMike
>
>
> "Bruce Mercer" < brucewm53remove@yaho
o.com> wrote in message
> news:SOOV4WHBHHA.2124@news-server...
>
>



Bruce Beacham

2006-11-10, 7:16 pm

Bruce Mercer wrote:
> Thanks Mike,
>
> Problem is.... a = 5mb 30,000 line CSV file.


(Untested - it's years since I did this <g> )
fl = new file()
fl.create("tempfile.csv")
fl.puts('"First line", "Next field", "etc"')
fl.close()
run copy tempfile.csv + originalfile.csv originalfile.csv
delete file tempfile.csv


Bruce Beacham
bigMike

2006-11-10, 7:16 pm

"Bruce Mercer"
> Thanks Mike,
>
> Problem is.... a = 5mb 30,000 line CSV file.


Picky, picky!

Obviously I was thinking of a much smaller text amount ;-)

I think Rich at AutoTracker has the right answer - only he posted it in
news.dbasetalk.com by accident, I think. Here is what he suggested:

********************
**********
I don't believe it is possible but you can read the entire file into a
memory variable, add your line to the beginning and save it. It seems to be
quite fast.
Rich...

local f
f = new file()
f.open(fName)
cStr = f.read(f.size(fName))
f.close()

cStr = "My New Line" + chr(13)+chr(10) + cStr

f.create(fName)
f.write(cStr)
f.close()
release object f
********************
*********


bigMike



Mervyn Bick

2006-11-11, 5:15 am

On Fri, 10 Nov 2006 22:23:26 +0200, bigMike <bigmikeaa@hotmail.com> wrot=
e:



> Picky, picky!


My turn to be picky. <g>


> I don't believe it is possible but you can read the entire file into a=


> memory variable, add your line to the beginning and save it. It seems =

to =

> be
> quite fast.
> Rich...
>
> local f
> f =3D new file()
> f.open(fName)
> cStr =3D f.read(f.size(fName))
> f.close()
>
> cStr =3D "My New Line" + chr(13)+chr(10) + cStr
>
> f.create(fName)
> f.write(cStr)
> f.close()
> release object f
> ********************
*********


create() overwrites an existing file so if anything goes wrong during th=
e =

write() then one could wind up with nothing. Rich didn't say so, probab=
ly =

because it is something he does automatically without thinking, but one =
=

should only delete original data, even if it is only for a second, if on=
e =

has an up-to-date backup copy "just in case".

Mervyn.

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com