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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

copy to text file

Status
Not open for further replies.

mferrer

Programmer
Apr 1, 2003
7
US
Is it possible to copy dbf file into a text file with only line feed as delimiter for records and no carriage return. I know the command copy to type sdf will copy it to text file but it also delimits the record with line feed and carriage return.

Your help is greatly appreciated
 
mferrer,
try something as (not tested, only for character fields!)

handle=fcreate('d:\mytext.txt')
IF handle < 0
wait window "unable to create file"
return
ENDIF
sele mydbf
scan
myrec = ""
FOR ii=1 to fcount()
myfield = field(ii)
myrec = myrec + &myfield
ENDFOR
=fwrite(handle,myrec+chr(10))
endscan
=fclose(handle)

Tesar
 
Tesar's approach will work fine for character fields, but you will probably have to accommodate other data types too.

Another way may be to combine the two:
Code:
CLOSE ALL
USE MyTable
COPY TO temp.txt SDF 
nInFile = Fopen('test.txt')
IF !nInFile  < 0
   nOutFile = Fcreate('new.txt')
   IF !nOutFile  < 0
      DO WHILE !Feof(nInFile)
         cTemp = ''
         =Fwrite(nOutFile, Fgets(nInFile)+ Chr(10)) 
      ENDDO 
   ENDIF 
ENDIF 
CLOSE ALL

-Dave Summers-
[cheers]
Even more Fox stuff at:
 
I have a similar problem and as yet have been unable to solve it, namely when I write a text file using low-level functions, every line includes an embedded LF & CR at end of line. I am not inputing from a table, just outputting values of variables to a text file. As of this date I have been unable to find a way to eliminate the CRs, even though I have spent many hours searching help, and many more hours testing different ways to solve the problem.

Will have to try the above to see if that solves my problem.

If it doesn't, I will post my code and see if anyone has a solution.


mmerlinn

"Political correctness is the BADGE of a COWARD!"

 
Geoff,
I think you're confused on forums here. There isn't a StrToFile() function in Fox 2.x.

mmerlinn,
FPUTS() automatically writes a CR/LF to the end of each record. FWRITE() doesn't.
Which are you using?


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top