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

Copying tables to text files

Status
Not open for further replies.

jbluhm

MIS
Sep 25, 2001
2
US
I am trying to copy a table to a text file which is no problem at all. The problem I am running into is that I do not want a line feed or carriage return at the end of my text file. Any ideas on how to accomplish this?


 
While there is no way to suppress these characters, it easy to "kill" them off in VFP 6.0.

SET SAFETY OFF
copy to ... file.txt
lcTemp = filetostr( "file.txt" )
lcTemp = Left(lcTemp, LEN(lcTemp)-2)
strtofile(lcTemp, "file.txt")
SET SAFETY ON

Rick
 
#DEFINE CRLF CHR(13)+CHR(10)

lcFile=FILETOSTR('C:\mypath\myfile.txt')
lnLast=OCCURS(CRLF,lcFile)

*To remove the last CRLF, use
lcFile=STRTRAN(lcFile,CRLF,'',lnLast)

*To remove ALL CRLFs, use
*lcFile=STRTRAN(lcFile,CRLF,'')

STRTOFILE(lcFile,'C:\mypath\myfile.txt') Jon Hawkins
 
I think that the suggestions above may work with V2.6 but if not low level file functions would allow you to manipulate the file -- check some of the examples in help or there have been a number of threads in the forum.
 
OK, here's on old program (written originally in FPD 2.0) that I used to strip off the final EOF character - also a problem for some non-DOS programs. You could make some minor changes to kill off the last 3 (?) characters which would include the CRLF (chr(13)+Chr(10)).

*!* STRIPASCIIEOF.PRG
LPARAMETERS qcFileName

* Open the file with unbuffered read/write access
lnhandle = FOPEN(qcFileName,12)

* Test for possible file opening error
IF lnhandle = -1
WAIT WINDOW "Error Opening File: " + ALLTRIM(qcFileName)TIMEOUT 10
RETURN
ENDIF

l_nSize = FSEEK(lnHandle,0,2) && Determine file size
= FSEEK(lnHandle, -1, 2) && Need to sneak a peak at the last character
l_nLastChar = INT(ASC(FREAD(lnHandle,1)))

IF l_nLastChar = chr(26) && ASCII eof [or 0x1A]
WAIT WINDOW "Stripping EOF" TIMEOUT 5 NOWAIT
l_nSize = l_nSize - 1
= FCHSIZE(lnHandle, l_nSize)
ENDIF

= FCLOSE(lnHandle)

RETURN


Rick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top