xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

FSeek()

Changes the position of the file pointer.

Syntax

FSeek( <nFileHandle>, <nBytes>, [<nOrigin>] ) --> nPosition

Arguments

<nFileHandle>
This is a numeric file handle returned from function FOpen(), FCreate(), or HB_FCreate().
<nBytes>
This is a numeric value specifying the number of bytes to move the file pointer. It can be a positive or negative number. Negative numbers move the file pointer backwards (towards the beginning of the file), positive values move it forwards. The value zero is used to position the file pointer exactly at the location specified with <nOrigin>.
<nOrigin>
Optionally, the starting position from where to move the file pointer can be specified. #define constants are available in the FILEIO.CH file that can be used for <nOrigin>.

Start positions for moving the file pointer
ConstantValueDescription
FS_SET *)0Start at the beginning of the file
FS_RELATIVE1Start at the current file pointer position
FS_END2Start at the end of the file

Return

The function returns a numeric value. It is the new position of the file pointer, counted from the beginning of the file (position 0).

Description

The low-level file function FSeek() moves the file pointer of an open file to a new position, without reading the contents of the file. The file pointer can be moved forwards (positive <nBytes>) and backwards (negative <nBytes>). It is not possible, however, to move the file pointer outside the boundaries of a file.

Info

See also:FClose(), FCreate(), FError(), FOpen(), FRead(), FReadStr(), FWrite(), HB_F_Eof()
Category: File functions , Low level file functions
Header:FileIO.ch
Source:rtl\philes.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example implements the user-defined function FSize()
// which determines the size of a file using FSeek()

   #include "FileIO.ch"

   PROCEDURE Main
      LOCAL cFile := "MyFile.txt"

      ? FSize( cFile )
   RETURN

   FUNCTION FSize( cFile )
      LOCAL nHandle := FOpen( cFile )
      LOCAL nSize   := -1

      IF FError() == 0
         nSize := FSeek( nHandle, 0, FS_END )
         FClose( nHandle )
      ENDIF
   RETURN nSize

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe