home *** CD-ROM | disk | FTP | other *** search
- ***************************************************************
- * * 07/26/92 DESKACC.PRG 9:31:22 *
- ***************************************************************
- * * *
- * * Description: *
- * * This program illustrates how to use the FSEEK *
- * * low-level I/O function *
- ***************************************************************
- SET TALK OFF
- CLOSE ALL && Close all files, etc. including low-level files
- STORE 0 TO BEGIN
- STORE 1 TO CURRENT
- STORE 2 TO END
- ***************************************************************
-
- ON ERROR DO FileError && Set error trap
- Handle = FOPEN("FOO.TXT",2) && Open file for read/write
- IF Handle < 0
- DO FileError
- RETURN
- ENDIF
- NewLoc = FSEEK(Handle, 0, END) && Move to end of file
- DO ShowAnswer WITH NewLoc, "Move to end of file"
- NewLoc = FSEEK(Handle, 0, BEGIN) && Move to beginning of file
- && (rewind)
- DO ShowAnswer WITH NewLoc, "Move to beginning of file"
- NewLoc = FSEEK(Handle, 50, BEGIN) && Move to before 51th byte
- DO ShowAnswer WITH NewLoc, "Move to 51th byte"
- NewLoc = FSEEK(Handle, 5, CURRENT) && Move 5 characters forward
- && from current position
- DO ShowAnswer WITH NewLoc, "Move 5 characters forward"
- NewLoc = FSEEK(Handle, -15, CURRENT) && Move 15 characters
- && backward from
- && current position
- DO ShowAnswer WITH NewLoc, "Move 15 characters backwards"
- NewLoc = FSEEK(Handle, 0, CURRENT) && Determine current position
- DO ShowAnswer WITH NewLoc, "Determine current position"
- NewLoc = FSEEK(Handle, 0) && Move to beginning of file
- DO ShowAnswer WITH NewLoc, "Move to beginning of file"
- ***********************************************************
- * Now change all occurrences of "cat" with "dog" in file
- DO WHILE .NOT. FEOF(Handle)
- Position = FSEEK(Handle, 0, CURRENT) && Save position
- String = FGETS(Handle)
- Position = FSEEK(Handle, Position, BEGIN ) && Move back
- String = STRTRAN(String, "cat", "dog", 1, 99)
- = FPUTS(Handle, String)
- ENDDO
- ENDIF
- ON ERROR
- = FCLOSE( Handle )
- ******************************************************************
- PROCEDURE FileError
- WAIT "File I/O Error #"+STR(FERROR()) WINDOW
- RETURN
- ******************************************************************
- PROCEDURE ShowAnswer
- PARAMETER Position, Message
- WAIT Message + " New file position: " ;
- +LTRIM(STR(Position)) WINDOW
- RETURN
-