Usina BRAdvPL Guide
Sign in
← All topics
FUNCTIONUnder review

FSeek

FSeek( nHandle, nOffSet, [nOrigem] ) --> nRet

Positions a file pointer in bytes.

FSeekAdvPL
01 · OVERVIEW

Overview

FSeek moves relative to FS_SET, FS_RELATIVE or FS_END and returns an absolute zero-based position. Seeking zero bytes from the end obtains size while changing the cursor. The community example uses this technique then returns to the start; the adaptation opens read-only, checks FError before continuing and closes its handle. File bytes are not characters and file position is not table RecNo. (TOTVS, n.d., ref. 1)

02 · SYNTAX

Syntax

FSeek( nHandle, nOffSet, [nOrigem] ) --> nRet

Parameters

nHandle
NumericRequired

Valid handle from FOpen/FCreate; zero is valid too.

nOffSet
NumericRequired

Byte offset.

nOrigem
NumericOptional

FS_SET=0, FS_RELATIVE=1, FS_END=2; start by default.

Return value

New absolute byte position from the start.

03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"
#Include "Fileio.ch"

User Function Ed396()
    Local nHandle := -1
    Local nError := 0
    Local nSize
    // Pre-existing fictional file in the test context; shared reading.
    nHandle := FOpen("editorial-test.txt", FO_READ + FO_SHARED)
    If nHandle < 0
        nError := FError()
        ConOut(cValToChar(nError))
    Else
        nSize := FSeek(nHandle, 0, FS_END)
        nError := FError()
        If nError == 0
            ConOut(cValToChar(nSize))
            // Reposition before any later read.
            FSeek(nHandle, 0, FS_SET)
        Else
            ConOut(cValToChar(nError))
        EndIf
        If !FClose(nHandle)
            ConOut(cValToChar(FError()))
        EndIf
    EndIf
Return Nil
Expected result

Test-file byte size or diagnostic; no fixed value assumed. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

BEST PRACTICES
  • Check path, permissions, platform and handle ownership. Close only handles obtained by this routine, including complete-application error handling.
  • Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Related content

REFERENCES
  1. TOTVS. FSeek. TDN. Accessed on 2026-10-26.
  2. EURAI. ADVPL/Funcoes/Arquivos de Disco/FSeek.PRW. universo_do_desenvolvedor_site, commit a5c83e9490302bdb4a0fc5a9d92c2d569a60773c. Exemplo analisado. Accessed on 2026-10-26.
Status
Under review
Page created on
Last reviewed on
Original language
Portuguese
Reviewed by
Usina.BR
0 approved comment(s)

Comments

There are no approved comments yet.

Sign in with Google or Microsoft to comment.

Powered by Usina Docs · Alpha