nHandleValid handle from FOpen/FCreate; zero is valid too.
AdvPL GuideFSeek( nHandle, nOffSet, [nOrigem] ) --> nRetPositions a file pointer in bytes.
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)
FSeek( nHandle, nOffSet, [nOrigem] ) --> nRetnHandleValid handle from FOpen/FCreate; zero is valid too.
nOffSetByte offset.
nOrigemFS_SET=0, FS_RELATIVE=1, FS_END=2; start by default.
New absolute byte position from the start.
#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 NilTest-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.
© 2026 Usina.BR. All rights reserved. TOTVS, Protheus, Microsiga and their respective logos are trademarks of their owners. AdvPL Guide is independent and uses limited, attributed excerpts justified by educational purposes. See the Terms of Use. Terms of Use
Comments
There are no approved comments yet.
Sign in with Google or Microsoft to comment.