xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

FClose()

Closes a binary file.

Syntax

FClose( <nFileHandle> ) --> lSuccess

Arguments

<nFileHandle>
The numeric file handle returned from a previous call to FOpen() or FCreate().

Return

The return value is .T. (true) when the file is successfully closed, otherwise .F. (false).

Description

FClose() closes a file that is either newly created with FCreate() or opened with FOpen(). Both functions return a numeric file handle that must be passed to FClose() in order to close the open file. When the file is successfuly closed, all internal file buffers are permanently written to disk, and the function returns .T. (true).

If the close operation fails, the return value is .F. (false). The reason for failure can then be queried by calling the FError() function.

Info

See also:FCreate(), FError(), FOpen(), FRead(), FSeek(), FWrite()
Category: File functions , Low level file functions
Source:rtl\philes.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example demonstrates how to create a new file, write
// some data to it and close it. If any operation fails, an
// appropriate error message is displayed along with the error
// code obtained from the operating system.

   #include "Fileio.ch"

   PROCEDURE Main
      LOCAL nFileHandle, cText

      nFileHandle := FCreate( "NewFile.txt", FC_NORMAL )

      IF FError() <> 0
         ? "Error while creatingg a file: ", FError()
         QUIT
      ENDIF

      cText  := "New text for file"
      IF FWrite( nFileHandle, cText ) <> Len( cText )
         ? "Error while writing a file: ", FError()
      ENDIF

      IF .NOT. FClose( nFileHandle )
         ? "Error while closing a file: ", FError()
      ELSE
         ? "File successfully created and closed"
      ENDIF
   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe