Kurt,
Beware embedded double quotes though as they will screw you up....do a
character substitution for blank or single quotes or the way I do it is to
delimit each field with "|" which is never normally used with data 

i.e. Copy to <filename> delimited with "|"

Also beware of memo fields as they will NOT be copied over to the csv file.

Dave Crozier

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf
Of Gilbert M. Hale
Sent: 01 August 2009 17:56
To: [email protected]
Subject: RE: Create a CSV file with VFP

There is a difference between what I regard as a true CSV file format, and a
simple comma delimited file format.  When I use the following syntax in VFP
I get what I regard as being a true CSV file format, with a twist depending
on whether I want the first record to have the field names or not:

COPY TO d:\path\TargetFile.csv CSV

First of all, in some situations I need to use a ".txt" extension instead of
".csv", so I almost always specify the extension in my target file name.
Also the output provided when I specify the delimited output format to be
"CSV" (as opposed to DELIMITED), the first line on the file is a list of the
fields from the source cursor, separated by commas.  But for the remaining
records any non-numeric value is "qualified" by being enclosed within double
quote characters, and the numeric values are delimited (separated) only
commas with no such qualification, like so:

cmake,cmodel,cnt_cmodel
"Acura","3.2TL",1
"Acura","Cl",2
"Acura","Integra",2
"Acura","Integra Coupe",1
"Audi","100",1
"Audi","100s",1
"BMW","325",1
"BMW","325i",1
"BMW","328i",1
"BMW","740i",1
"Boat Trailer","Trail Duster",1
"Buick","Century",64
"Buick","Electra",1
"Buick","Enclave",3
"Buick","Estate Wagon",2
"Buick","LaCrosse",12
"Buick","LeSabre",82
"Buick","Lucerne",4
"Buick","Park Avenue",18

The advantage of having character field enclosed within double quotes is
that any nested commas within a field will not fool a file import routine
into thinking the embedded comma is a delimiter.  Hence, I see a clear
difference between a comma delimited file and a CSV file where non-numeric
field values are qualified (with double quotes in this case).

Were I to use the syntax that follows, I would NOT get field names in the
first output line in the target file, but I would still get the non-numeric
fields qualified with double quote characters.  And the default file name
would get the ".txt" extension (although I could fully qualify the target
file name with a different extension value I may want to have).

COPY TO Z d:\path\TargetFile.txt DELIMITED


"Acura","3.2tl",1,"x"
"Acura","Cl",2,"x"
"Acura","Integra",2,"x"
"Acura","Integra Coupe",1,"x"
"Audi","100",1,"x"
"Audi","100s",1,"x"
"BMW","325",1,"x"
"BMW","325i",1,"x"
"BMW","328i",1,"x"
"BMW","740i",1,"x"
"Boat Trailer","Trail Duster",1,""
"Buick","Century",64,""
"Buick","Electra",1,""


I hope that helps...

Gil


 

> -----Original Message-----
> From: [email protected] [mailto:profoxtech-
> [email protected]] On Behalf Of G Gambill
> Sent: Saturday, August 01, 2009 12:24 PM
> To: [email protected]
> Subject: Create a CSV file with VFP
> 
> I need to create a “.CSV” file using VFP. Opening a CSV file with
> notepad
> allows me to infer that is is a simple comma delimited .TXT file and
> can be
> created easily with low level code. The fact that it is called other
> than
> TXT (.CSV) tells me otherwise.
> 
>  Anyone have experience and/or suggestions here?
> 
> TIA
> 
> George
> 
> 
> --- StripMime Report -- processed MIME parts ---
> multipart/alternative
>   text/plain (text body -- kept)
>   text/html
> ---
> 
[excessive quoting removed by server]

_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/profox
OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech
Searchable Archive: http://leafe.com/archives/search/profox
This message: 
http://leafe.com/archives/byMID/profox/113182bfc17544bb96b75ec977c5e...@develop
** All postings, unless explicitly stated otherwise, are the opinions of the 
author, and do not constitute legal or medical advice. This statement is added 
to the messages for those lawyers who are too stupid to see the obvious.

Reply via email to