Using Low-Level I/O to Remove Leading CR/LF Created by LISTLast reviewed: April 30, 1996Article ID: Q129401 |
The information in this article applies to:
SUMMARYThe LIST TO FILE <filename> command places a CR/LF at the beginning of the file <filename>. If the file created is used as input to another program, it may be necessary to programmatically remove these two leading bytes. One way of doing this is through the use of low-level file I/O functions.
MORE INFORMATIONThe following code is an example of how to use low-level file functions to alter a text file that begins with a carriage return/line feed pair.
* open the tutorial database 'CUSTOMER' CLOSE ALL CLEAR ALL USE customer * create the text file LIST TO FILE output.txt FOR state="FL" * Now the text file has a leading CR/LF at the beginning. * To get rid of this, do the following: handle=FOPEN("output.txt",12) && low level open, read/write IF handle > 0 && do you have a good open? * When opened, file pointer points at beginning of file. * To get size of file, seek end of file, return the number of bytes * the pointer was moved SIZE=FSEEK(handle,0,2) FOR LOOP=2 TO SIZE =FSEEK(handle,LOOP,0) && go to data byte to be copied the_char = FREAD(handle,1) =FSEEK(handle,LOOP-2,0) && where to write the data =FWRITE(handle,the_char,1) && write the character ENDFOR * Now that the data in the file has been migrated two * bytes down to cover up the CR/LF at the beginning * of the file, readjust the size of the file to * truncate the two garbage bytes at the end of the file =FCHSIZE(handle,SIZE-2) =FCLOSE(handle) && done ENDIF |
Additional reference words: VFoxWin 3.00 2.60a FoxWin hard return cr / lf
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |