Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Append to the top of a txt file

Status
Not open for further replies.

chandler

MIS
Dec 10, 2000
66
US
I would like to append a header row to the top of a txt file without using copy to file type csv. The header row column names will contain spaces and characters not allowed in dbf column names. I tried using SET ALTERNATE ON ADDITIVE, but that appends to the bottom of the file.

What I'm trying to do is break up a file into 10,000 record chunks if the qnty is over 15,000. Using type csv puts the dbf header name at the beginning of each record, but I need a different header which can be seen between the TEXT..ENDTEXT lines.

The specific code of what I'm doing is here:

if qnty>14999
for x=1 to qnty step 10000
goto x
incr=incr+1

copy next 10000 to "d:\lists\"+print_jobs(acnt,1)+"_"+alltrim(str(incr))+".txt" type delimited

SET ALTERNATE TO "d:\lists\"+print_jobs(acnt,1)+"_"+alltrim(str(incr))+".txt" ADDITIVE 2
SET ALTERNATE ON
SET CONSOLE OFF

TEXT
"FIRST","LAST","Or Current Resident","STREET","CITY","ST","ZIP4","JOBNUM","Part","Opt. Endorsement Line","POSTNET Barc","Sequenti","Sch","StudentID","VAR1","VAR2"
ENDTEXT

SET ALTERNATE OFF
CLOSE ALTERNATE
SET CONSOLE ON

next
else
endif

ENDFOR


Thanks!

Chandler
I ran over my dogma with karma!
 
You can SET HEADINGS OFF to turn off the heading that VFP puts above the data. If you want your own heading first, why not just put the TEXT...ENDTEXT section before your COPY command?


-BP (Barbara Peisch)
 
The append command adds data to the bottom. You can add a field for the header and detail records though, and create an index on it.

* example
RecType C(1)

Set rectype to "1" for a header record and "9" for a detail record (or something like that) and then set the order of the table and go top.

SET ORDER TO recType
GO TOP
BROWSE



Jim Osieczonek
Delta Business Group, LLC
 
Chandler,

I forgot that there is no ADDITIVE clause with the COPY TO command. My solution won't work. You can go with Jim's solution, or build up the data you want in a memory variable and use STRTOFILE to write it out.


-BP (Barbara Peisch)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top