Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
COPY TO DELIMITED - field headers?
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01016259
Message ID:
01016295
Views:
6
>>If you COPY TO file XLS, you get field headers. If you do COPY TO textfile DELIMITED WITH TAB,
>>though, you just get the data. Is there any way to get around this short of manually writing
>>out the fields as the first record? Thanks.
>You may issue:
>go bott
>copy to ... csv next 1 && get the header

That's reasonably efficient. Thanks!
lcTable = GETFILE("DBF", "Table:", "Open", 0, "Select file to export")
lcExport = PUTFILE("Export to:", FORCEEXT(lcTable, "TXT"), "TXT")

lcTempFile = SYS(3)


USE (lcTable)
COPY TO (lcTempFile) CSV NEXT 0
lcHeaders = FILETOSTR(FORCEEXT(lcTempFile, "CSV"))
lcHeaders = STRTRAN(lcHeaders, [,], ["]+CHR(9)+["])
lcHeaders = ["] + LEFT(lcHeaders, LEN(lcHeaders) - 2) + ["]

COPY TO (lcTempFile) DELIMITED WITH TAB 

lcOutFile = lcHeaders + CHR(13) + CHR(10) + FILETOSTR(lcTempFile + ".txt")
STRTOFILE(lcOutFile, lcExport)

ERASE &lcTempFile..csv
ERASE &lcTempFile..txt
My blog
My consulting page
My home page

Member of the Trim Your Auto-Quote Campaign!
What's another word for thesaurus?
Previous
Reply
Map
View

Click here to load this message in the networking platform