CFile:Printf CFile:FilePos

CFile:Seek


The Seek method sets the byte offset of the file read/write position.

Syntax

nPos = CFile:Seek( nBytes, nFromWhere )

    nBytes is the distance to move the file pointer.

    nFromWhere specifies the position from which to move (see Remarks).

    On success, bSuccess returns nPos, the byte offset of the file position.

    On failure, this method returns -1.

Remarks

The nFromWhere argument has 3 possible values that specify the reference point from which to offset the file pointer. You can specify the reference point using predefined CFile member names or you can use the numeric values listed in the table below. Note that the CFile Member values are specified using the particular instance of the class, such as F, and not the class name CFile. In addition, a dot is used, not a colon, to separate the class instance name and the member name. For example, if a CFile instance is named F, then use F.nBegin. Alternatively, you can use the value 0, which means the same thing. However, using the value 0 makes the script less "user friendly".

Values of the nFromWhere Parameter

CFile Member

Value

Reference Position

nBegin

0

Beginning of file

nCurrent

1

Current position

nEnd

2

End of file

Example

Suppose a CFile F exists and that the file pointer is at byte offset 54. The following script fragment advance the file writing position to byte offset 80:

 

Printf("pos = %d", F:FilePos() )

-- result: pos = 54

F:Seek( 26, F.nCurrent )

-- advance the file position by 26 bytes

Printf("pos = %d", F:FilePos() )

-- result: pos = 80

Related Topics

CFile, FilePos