ULSEEK Function

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.

Format

ULSEEK(FileHandle, n,{0|1|2})

Description

ULSEEK positions the file pointer in FileHandle n bytes from either the beginning, current, or ending position in the file. The offset (n) can have a positive, negative, or zero value. Use a negative offset to move the file pointer backwards (towards the beginning of the file.) To position the pointer at the exact beginning or the exact end of the file, or to read its position without moving it, use an offset of zero.

To indicate where the offset is to start, specify one of the following as the second parameter:

0

Beginning of the file.

1

Present position of the file pointer.

2

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.

Examples

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 next example opens the file \books\chap3.txt 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 (ULSEEK or UREAD) failed.

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

See Also

O/S Interoperability Commands

UCLOSE Command

UCREATE Command

UDELETE Command

UERROR Function

UEXECUTE Command

ULOCK Command

UMESSAGE Command

UOPEN Command

UREAD Command

UREADLINE Function

USYSTEM Function

UWAITFOR Command

UWRITE Command