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

End of file character on text files

Status
Not open for further replies.

AndrewMozley

Programmer
Oct 15, 2005
623
GB
I am using Clipper 5.2 to generate an output text file (of BACS transfers). My general approach is :

SET CONSOLE OFF
SET ALTERNATE TO &lFileName
SET ALTERNATE ON
?? "First line"
. . . .
? "Last line"
SET ALTERNATE OFF
SET ALTERNATE TO
SET CONSOLE ON

I see that there is a SUB character (Hex '1A') at the end of the file and I don't believe that I put it there.

It has all worked fine and been acceptable for years, but now the bank does not like the last character. Any ideas how I can suppress this from the file? I can edit it with Microsoft Word (as text) but that always appears to put an extra CRLF at the end, and anyway I can hardly make the user do that every time!

Thanks. Andrew Mozley
 
try this:

Code:
memowrit(lFileName,strtran(MemoRead(lFileName),chr(26),""))

Regards

Griff
Keep [Smile]ing
 
Hi, GriffMG

As far as I know memowrit still puts out the DOS eof character hex 1A. I tried your method here and it didn't work for me.

I have always used low level file I/O to accomplish this.

eg: xhnd=fcreate('filename.txt')
if xhnd>0
fwrite(xhnd,xbuffer)
fclose(xhnd)
endif

Where xbuffer contains the data to write, with CRLF's at the end of each line. If there is too much data to put in one string var then put the fwrite in a loop.

You can also accomplish it by creating the file like you do now, then fopen it and fread the length of the file -1 and fwrite that back.

Jock
 
Ah, I'm thinking VFP in the Clipper thread!

Sorry!

Regards

Griff
Keep [Smile]ing
 
I found that using direct file access didn't append the chr(26)

* use direct file handling as ALTERNATE added a chr(26)
* which I didn't want
if (nHandle:=fcreate(cFile+'.csv', FC_NORMAL)) != -1

cText:=alltrim(fieldget(1)) // assumes character
if at(',', cText)>0
cDelim:='"'
else
cDelim:=''
endif
if at('"', cText)>0
strtran(cText, '"', '""')
endif

fwrite(nHandle, cDelim+cText+cDelim)

fclose(nHandle)

else
lError:=TRUE
? 'Create error: '+str(ferror())
endif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top