Click or drag to resize

FSeek Function

Set the file pointer to a new position.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.08
Syntax
 FUNCTION FSeek(
	 ptrHandle AS USUAL,
	 nOffset AS USUAL,
	 kOrigin AS USUAL
) AS LONG
View Source

Parameters

ptrHandle
Type: Usual
The handle of the open file.
nOffset
Type: Usual
The number of bytes to move the file pointer, from the position defined by <nOrigin>.  It can be a positive or negative number.  A positive number moves the pointer forward in the file, and a negative number moves the pointer backward.  If <nOrigin> is the end-of-file, <nOffset> must be 0 or negative.
kOrigin
Type: Usual
One of the following constants indicating the starting location of the file pointer, telling where to start searching the file:
Constant Seeks From
FS_END End-of-file
FS_RELATIVE Current pointer position
FS_SET Beginning-of-file (default)

Return Value

Type: Int32
The new position of the file pointer, relative to the beginning of the file (position 0).  (The original position of the file pointer does not matter.)
Remarks
FSeek() is a low-level file function that moves the file pointer forward or backward in an open file without actually reading the contents of the specified file.  The file pointer cannot be moved beyond the beginning or end-of-file boundaries.
Remarks
Tip Tip
This function is included for compatibility. We do not recomment using static memory for file i/o operations. We recommend that you use the function overload that takes a byte array parameter in stead.
Examples
This example uses FSeek() to determine the length of a file by seeking from the end-of-file.  Then, the file pointer is reset to the beginning-of-file:
X#
// Open the file read-only
IF (ptrHandle := FOpen2("temp.txt", FO_READ)) != F_ERROR
        // Get length of the file
        nLength := FSeek(ptrHandle, 0, FS_END)
        // Reset file position to beginning-of-file
        FSeek(ptrHandle, 0)
        FClose(ptrHandle)
ELSE
        ? DOSErrString(FError())
ENDIF
This example positions the file pointer at the last byte in a file:
X#
FUNCTION FileBottom(ptrHandle) AS LONGINT
        RETURN (FSeek(ptrHandle, 0, FS_END))
This example positions the file pointer at the first byte in a file (same as the Rewind() function):
X#
FUNCTION FileTop(ptrHandle) AS LONGINT
        RETURN (FSeek(ptrHandle, 0))
See Also