次の方法で共有


FSEEK( ) Function

Moves the file pointer in a file opened with a low-level file function.

FSEEK(nFileHandle, nBytesMoved [, nRelativePosition])

Parameters

  • nFileHandle
    Specifies the file handle for the file in which FSEEK( ) moves the file pointer. A file handle number is returned by FCREATE( ) or FOPEN( ) when the file is created or opened.

  • nBytesMoved
    Specifies the number of bytes to move the file pointer. The file pointer is moved toward the end of the file if nBytesMoved is positive. The file pointer is moved toward the beginning of the file if nBytesMoved is negative.

  • nRelativePosition
    Moves the file pointer to a relative position in the file. By default, the file pointer is moved relative to the beginning of the file. You can also move the file pointer relative to the current file pointer or the end of the file by including nRelativePosition. The following table lists values for nRelativePosition and from where the file pointer is moved.

    nRelativePosition

    Moves the file pointer relative to

    0

    (Default) The beginning of the file.

    1

    The current file pointer position.

    2

    The end of the file.

Return Value

Numeric

Remarks

After moving the file pointer, FSEEK( ) returns the number of bytes the file pointer is positioned from the beginning of the file. The file pointer can also be moved with FREAD( ) and FWRITE( ).

Example

The following user-defined function uses FSEEK( ) to return the size of a file. If you don't pass parameters to the user-defined function, it returns –2. If the file cannot be found, the user-defined function returns –1.

FUNCTION fsize2
PARAMETERS gcFileName  && File to be checked
PRIVATE pnHandle,pnSize
IF PARAMETERS( ) = 0
   RETURN -2  && Return -2 if no parameter passed
ELSE
   IF !FILE(gcFileName)
      RETURN -1  && Return -1 if file does not exist
   ENDIF
ENDIF
pnHandle = FOPEN(gcFileName)   && Open file
pnSize = FSEEK(pnHandle,0,2)   && Determine file size, assign to pnSize
=FCLOSE(pnHandle)  && Close file
RETURN pnSize  && Return value

See Also

Reference

FCHSIZE( ) Function

FCLOSE( ) Function

FCREATE( ) Function

FEOF( ) Function

FFLUSH( ) Function

FGETS( ) Function

FOPEN( ) Function

FPUTS( ) Function

FREAD( ) Function

FWRITE( ) Function

Other Resources

Functions

Language Reference (Visual FoxPro)