Click or drag to resize

FSeek Function

X#
Set the file pointer to a new position.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.19
Syntax
 FUNCTION FSeek(
	ptrHandle,
	nOffset,
	kOrigin
) AS LONG CLIPPER
Request Example View Source

Parameters

ptrHandle (Optional)
Type: Usual
The handle of the open file.
nOffset (Optional)
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 (Optional)
Type: Usual
One of the following constants indicating the starting location of the file pointer, telling where to start searching the file:
ConstantSeeks from
FS_ENDEnd-of-file
FS_RELATIVECurrent pointer position
FS_SETBeginning-of-file

Return Value

Type: Long
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#
 1// Open the file read-only
 2IF (ptrHandle := FOpen2("temp.txt", FO_READ)) != F_ERROR
 3    // Get length of the file
 4    nLength := FSeek(ptrHandle, 0, FS_END)
 5    // Reset file position to beginning-of-file
 6    FSeek(ptrHandle, 0)
 7    FClose(ptrHandle)
 8ELSE
 9    ? DOSErrString(FError())
10ENDIF
This example positions the file pointer at the last byte in a file:
X#
1FUNCTION FileBottom(ptrHandle) AS LONGINT
2    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#
1FUNCTION FileTop(ptrHandle) AS LONGINT
2    RETURN (FSeek(ptrHandle, 0))
See Also