F - Petewg/harbour-core GitHub Wiki

Back to Home

Note: Functions starting with F***() designated for use on database/fields handling operations, (that is, all functions from FCount() / FieldBlock() to Found()) have been moved in a separate page, grouped together with the db*** functions. Please click here to visit that page...

Legacy File I/O functions

  • FClose(<nHandle>) lError returns true (.T.) or (.F.) if an error occured (e.g.: when an invalid handle used). <nHandle> is the file handle obtained previously from 'FOpen() or 'FCreate()'.

  • FCreate(<cFile, [<nAttibute>]) nHandle
    attempts to create a new binary file. returns the file handle number if succesful or -1 on failure and FError() is set to indicate an error code. <cFile> is the name of the file to create. If the file already exists, its length is truncated to zero without warning. <nAttribute> is one of the binary file attributes and can be: 0=Create normal read/write file (default), 1=Create read-only file, 2=Create hidden file, 4=Create system file. (refer to 'Fileio.ch' for defined constants).

  • FErase(<cFile>) nSuccess
    returns 0 on success or -1 on failure. FError() can be used to determine the nature of the error. <cFile> is the name of the file to be deleted from disk, including extension, optionally preceded by a drive and/or path specification. The function does not use either SET DEFAULT or SET PATH to locate <cFile>. Warning! Files must be CLOSEd before removing them with FErase().

  • FError() nErrorCode
    returns the DOS error from the last file operation as an integer numeric value. If there is no error, returns zero.

  • File(<cFileSpec>) lExist
    checks if a file exists. Supports wildcards, does NOT recognize hidden and/or system files. If the <cFileName> does not include a path, then it searches with this order into: the current directory, the directory set with SET DEFAULT, the directories listed in the SET PATH setting.

  • FOpen(<cFileName>, [<nMode>]) nHandle
    returns a file handle or -1 when the operation fails. The cause of failure can be determined by 'FError()'.
    <cFileName> is the file to be opened while optional param <nMode> defines one or more opening modes as defined into fileio.ch header file.
    For detailed documentation about FOpen(), please take a look at Harbour Reference Guide .

  • FRead(<nFileHandle>, @<cBuffer>, <nBytes>) nBytes
    reads <nBytes> characters from a binary file into <cBuffer> variable. Returns the number of bytes read. If the number is less than <nBytes> either the end of file is reached, or a file read error ocurred.

  • FReadStr(<nHandle>, <nBytes>) cString reads characters from an open binary file beginning with the current file pointer position. Characters are read up to <nBytes> or until a null character CHR(0) is encountered. All characters are read including control characters except for CHR(0). The file pointer is then moved forward <nBytes>. If <nBytes> is greater than the number of bytes from the pointer position to the end of the file, the file pointer is positioned to the last byte in the file.

  • FRename(<cOldFile>, <cNewFile>) nSuccess
    changes the name of a specified file to a new name. <cOldFile> is renamed only if it is located in the current directory or in the specified path. Any SET DEFAULT or SET PATH are ignored. If the source directory is different from the target directory, the file is moved to the target directory. In the instance that either <cNewFile> exists or is currently open, function fails and returns -1. Use FError() to determine the exact error. Warning! Files must be CLOSEd before renaming. Attempting to rename an open file will produce unpredictable results. When a database file is renamed, the associated memo file (if any) must also be renamed otherwise the integrity of database(s) may be compromised.
    See also: hb_vfRename()

  • FSeek(<nHandle>, <nOffset>, [<nOrigin>]) nPosition
    moves the file pointer forward or backward in an open binary file without actually reading the contents. <nHandle> is the file handle obtained from 'FOpen()', or 'FCreate()'. <nOffset> is the number of bytes to move the file pointer from the position defined by <nOrigin>. A positive number moves the pointer forward, and a negative number moves the pointer backward in the file. <nOrigin> defines the starting location of the file pointer. The default value is zero, representing the beginning of file. If <nOrigin> is the end of file, <nOffset> must be zero or negative.

  • FWrite(<nHandle>, <cBuffer>, [<nBytes>]) nBytesWritten
    returns the number of bytes written and should be equal to <nBytes>. If it is lesser or zero, an error occurred.
    <nHandle> is the file handle obtained from 'FOpen()' or 'FCREATE()'. <cBuffer> is the character string to be written. <nBytes> are the number of bytes to be written beginning at the current file pointer position. If omitted, the entire content of <cBuffer> is written.

Back to Home

⚠️ **GitHub.com Fallback** ⚠️