The ulseek() function moves the file pointer in an open file and returns the position of the file pointer, which is the number of bytes from the beginning of the file.
ULSEEK(FileHandle, n,{0|1|2})
The ulseek() function positions the file pointer in FileHandle n bytes from either the beginning, current, or ending position in the file.
To indicate where the offset should start, specify one of the following as the second parameter:
0 | The position of the file pointer is at the beginning of the file. |
1 | Present position of the file pointer. |
2 | The position of the file pointer is at the end of the file. |
The value returned is the absolute location of the file pointer from the beginning of the file, measured in bytes. If an error occurs, a value of -1 is returned.
ULSEEK (FileHandle, 0, 2) | Points to the end of a file. |
ULSEEK (FileHandle, 0, 0) | Points to the beginning of a file. |
ULSEEK (FileHandle, -8, 2) | Points to the eighth byte before the end of the file. |
ULSEEK (FileHandle, 0, 1) | Returns the current file pointer position. |
The following example opens the \books\chap3.txt file for reading and reads the last 50 bytes of the file into the variable VAR2. If it is unable to do this, it prints an error message telling which inter-operating system command failed (ulseek or uread).
FILENAME="c:\books\chap3.txt" UOPEN FILENAME FOR READ TO FILEDES ELSE PRINT "Unable to open ":FILENAME STOP END * Use ULSEEK to move pointer 50 bytes in * from end of file VAR1=ULSEEK(FILEDES,-50,2) IF (VAR1<>-1) THEN * Now move read last 50 bytes UREAD VAR2 FROM FILEDES FOR 50 ELSE PRINT "Unable to read ":FILENAME GOTO EOJ: END END ELSE PRINT "Ulseek failed on file ":FILENAME GOTO EOJ: END