xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

HB_FCreate()

Creates and/or opens a binary file.

Syntax

HB_FCreate( <cFileName>, [<nFileAttr>], [<nOpenFlags>] ) --> nFileHandle

Arguments

<cFilename>
This is a character string holding the name of the file to create. It must include path and file extension. If the path is omitted from <cFileName>, the file is created in the current directory.
<nFileAttr>
A numeric value specifying one or more attributes associated with the created or opened file. #define constants from the FILEIO.CH file can be used for <nFileAttr> as listed in the table below:

Attributes for binary file creation
ConstantValueAttributeDescription
FC_NORMAL *)0NormalCreates a normal read/write file
FC_READONLY1Read-onlyCreates a read-only file
FC_HIDDEN2HiddenCreates a hidden file
FC_SYSTEM4SystemCreates a system file

<nOpenFlags>
A numeric value specifying one or more flags indication how to create a new or open an existing file #define constants from the FILEIO.CH file can be used for <nOpenFlags> as listed in the table below:

Flags for file opening or creation
ConstantValueDescription
FO_COMPAT *)0Compatibility mode
FO_EXCLUSIVE16Exclusive use
FO_DENYWRITE32Prevent other applications from writing
FO_DENYREAD48Prevent other applications from reading
FO_DENYNONE64Allow others to read or write
FO_SHARED64Same as FO_DENYNONE
FO_CREAT0x0100Create and open file
FO_TRUNC0x0200Open existing file and truncate it
FO_EXCL0x0400Create and open only if the file does not exist

Return

The function returns a numeric file handle to be used later for accessing the file using FRead() or FWrite(). The return value is -1 when the operation fails. Use FError() to determine the cause of failure.

Description

The low-level file function HB_FCreate() is a combination of FCreate() and FOpen(). HB_FCreate() opens an existing file or creates a new one.

If <cFileName> specifys an existing file, the third parameter <nOpenFlags> can be used to indicate if the file should be truncated, i.e. all data should be removed from the file after opening.

Refer to FRead() and FWrite() for examples that read or write data to a binary file using a file handle returned from HB_FCreate().

Info

See also:FCreate(), FOpen(), HB_FCommit(), HB_F_Eof()
Category: File functions , Low level file functions , xHarbour extensions
Header:FileIO.ch
Source:rtl\philes.c
LIB:xhb.lib
DLL:xhbdll.dll


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