×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Microsoft: FoxPro FAQ

Program Source Code

How to strip the DOS EOF (0x1A) character from the end of a file by rgbean
Posted: 2 Feb 04

I've found that most programs that don't like the EOF character at the end of a text file, also don't like a trailing CRLF. If you don't have this problem, kill that part of the code. If you want to "see" it happen, undelete the * on the WAITs.

*!* STRIPEOF.PRG
PARAMETERS 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
l_nOrgSize = l_nSize && save so we know if we've stripped anything
= FSEEK(lnHandle, -3, 2) && Sneak a peak at the last 3 characters
l_cLastChars = FREAD(lnHandle,3)
l_nLastChar = INT(ASC(SUBSTR(l_cLastChars,3,1)))

IF l_nLastChar = 26 && 0x1A && ASCII eof [or CHR(26)]
   *WAIT WINDOW "Stripping EOF" TIMEOUT 5 NOWAIT
   l_nSize = l_nSize - 1
   l_cLastChars = LEFT(l_cLastChars, 2) && throw away last
ENDIF

IF RIGHT(l_cLastChars, 2) = CHR(13)+CHR(10) && CRLF
   *WAIT WINDOW "Stripping CRLF" TIMEOUT 5 NOWAIT
   l_nSize = l_nSize - 2
ENDIF

IF l_nSize <> l_nOrgSize
   = FCHSIZE(lnHandle, l_nSize) && make it shorter
ENDIF

= FCLOSE(lnHandle)

RETURN


Back to Microsoft: FoxPro FAQ Index
Back to Microsoft: FoxPro Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close