In Visual Foxpro, I am trying to create a CSV file using the COPY TO command with TYPE CSV, but do not want header fields on top of the output file.
Furthermore, I am also trying to attach a COMMA after every row.
Current Output
f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17
"0","49162","0","0","0","0","0","0","0","0","0","0","0","0",2.1, "02/14/2006"
"0","49162","0","0","0","0","0","0","0","0","0","0","0","0",2.1, "02/14/2006"
"0","49162","0","0","0","0","0","0","0","0","0","0","0","0",2.1, "02/14/2006"
Desired Output
"0","49162","0","0","0","0","0","0","0","0","0","0","0","0",2.1, "02/14/2006",
"0","49162","0","0","0","0","0","0","0","0","0","0","0","0",2.1, "02/14/2006",
"0","49162","0","0","0","0","0","0","0","0","0","0","0","0",2.1, "02/14/2006",
--------------------------------------------------------------------------------------------------
Can someone please help me.
If it's not possible to create in VFoxpro can I use DTS to get the desired output. Source:DBF and Destination:TXT file. What will be the row delimiter in DTS package

COPY TO CommandHi Cetin,
mrtrombone
Hard to believe how one can err that much! :(
Sor..ree!
lsgko
Suchat,
That was the typo:) Your code eliminates ". In original question it was shown as the required output.
Dullax
COPY TO TextFile.TXT TYPE DELIMITED
cContents = FileToString("TextFile.TXT")
nLines = ALINES(aFileLines, cContents)
cNewContents = ""
FOR nLine = 1 TO nLines
cNewContents = cNewContents = aFileLines[nLine] + "," + CHR(13) + CHR(10)
ENDFOR
StringToFile(cNewContents, "TextFile.TXT")
This is untested, but should give you the idea.
Tamar
Peter Aspect
STRTOFILE
(strtran(FILETOSTR("myfile.txt"),'""'+CHR(13)+CHR(10),CHR(13)+CHR(10)),'myFile.txt')Joe_D
First what you needed was not a CSV. It's called DELIMITED (and having a header or not is the difference between a CSV and a DELIMITED file). Having an extra comma at the end is ismply a matter having an extra dummy coulumn in source:
select f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,"" from myTable into cursor myCursor
copy to myFile.txt type delimited
PS: Select actually is not needed but seeing your comment at the bottom I think you'd understand this one better.
JennerJenner
Suchat,
But this would produce different results depending on version (and error in some even after correcting the typo in code). Also "" and , are defaults for "type delimited".
JessicaElise
It definitely gave me the idea!!!
Thanks very much Tamar!!!
Hajik
Ian Cross
I 've only VFP8 and VFP9 to test with. I don't think there is any typo in it, the command work as
expected without error. But, I am not sure for other version.
In fact, the [ WITH CHARACTER , ] in the copy command is not necessary for this particular case.
I used [ DELIMITED WITH "" WITH CHARATER | ] in my application to produce data in this format
charfield1|numfield2|datefield3
Though the " and , is the default for TYPE DELIMITED, but I'd found out that 2 double quote somehow
eliminated the " delimiter from the result altogether. It is a special case for "". Try experiment with other
character e.g. 2 single quote or a vertical bar. Those will give the "usual" result.
Deobrat Singh
With slight modifications to your suggestion I was able to make it work.
Wouldn't have done it so quickly without your help and this forum.
Many thanks Cetin. Really appreciate it.
Hajik
bouldercrazy
select f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15,f16,f17,"" from myTable into cursor myCursor
copy to myFile.txt DELIMITED WITH "" WITH CHARACTER ,
The "" is 2 quote character (ASCII 34) and the , is a lone comma.
KristinBarker
Thanks Cetin. This is very helpful. There's one minor issue... Now I am getting an extra set of quotation marks at the end of each row. How can I get rid of that
"0","49162","0","0","0","0","0","0","0","0","0","0","0","0",2.18,"02/14/2006"," 08:00:00"," "
"0","49162","0","0","0","0","0","0","0","0","0","0","0","0",2.57,"02/14/2006"," 10:11:00"," "
Thanks for your help!