Usina BRAdvPL Guide
Sign in
← All topics
FUNCTIONUnder review

FOpen

FOpen( cArq, [nModo], [xParam3], [lChangeCase] ) --> nRet

Opens an existing file and returns its handle.

FOpenAdvPL
01 · OVERVIEW

Overview

FOpen does not create missing files. nModo combines Fileio.ch access and sharing flags; this example chooses shared read-only access whereas the community source requests read/write. Handle zero is valid and -1 is failure. The page states lookup does not follow AdvPL Set Default/Set Path; lChangeCase matters for case-sensitive names. editorial-test.txt must exist in the test context; the fragment closes only its own handle. (TOTVS, n.d., ref. 1)

02 · SYNTAX

Syntax

FOpen( cArq, [nModo], [xParam3], [lChangeCase] ) --> nRet

Parameters

cArq
CharacterRequired

Filename with path when needed.

nModo
NumericOptional

Fileio.ch access + sharing.

xParam3
AnyOptional

Compatibility: Nil.

lChangeCase
LogicalOptional

Filename case handling according to build/configuration.

Return value

Handle >= 0; -1 on failure.

03 · PRACTICAL EXAMPLE

Commented example

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

User Function Ed388()
    Local nHandle := -1
    Local nError := 0

    // 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
        ConOut("File opened for reading")
        If !FClose(nHandle)
            ConOut(cValToChar(FError()))
        EndIf
    EndIf
Return Nil
Expected result

Open message followed by closure, or a failure code. 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. FOpen. TDN. Accessed on 2026-10-26.
  2. EURAI. ADVPL/Funcoes/Arquivos de Disco/FOpen.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