FILE/IO

Name

FILE/IO -- 

Function

nFiles              ADIR([<cFilespec>],[<aFilenames>],[<aSizes>],[<aDates>], [<aTimes>],[<aAttributes>])
lRet                bZip2Close(<nHandle>)
nHandle             bZip2Open(<filename> [,<mode>])
realLen             bZip2Read(<nHandle>, <@cBuffer> [,<nLen>])
realLen             bZip2Write(<nHandle>, <cBuffer> [,<nLen>])
cDirectory          CURDIR([<cDrivespec>])
nSuccess            DIRCHANGE(<cDir>)
aDirectory          DIRECTORY(<cDirSpec>, [<cAttributes>])
nOsCode             DOSERROR([<nNewOsCode>])
<sDosFileName>      DOSPATH(<sUnixFileName>)
TRUE || FALSE       FACCESS(<sFileName>, <sMode>)
lError              FCLOSE(<nHandle>)
nHandle             FCREATE(<cFile>, [<nAttribute>])
nSuccess            FERASE(<cFile>)
nErrorCode          FERROR()
                    
lExists             FILE(<cFilespec>)
                    
<sFileAttrs>        FILEATTRS(<sFileName>)
<sFileStr>          FILEGETSTR(<nFileHandle>, <nSize>)
nHandle             FOPEN(<cFile>, [<nMode>])
nBytes              FREAD(<nHandle>, @<cBufferVar>, <nBytes>)
cString             FREADSTR(<nHandle>, <nBytes>)
nSuccess            FRENAME(<cOldFile>, <cNewFile>)
nPosition           FSEEK(<nHandle>, <nOffset>, [<nOrigin>])
NIL                 FT_DFCLOSE()
nResult             FT_DFSETUP( <cInFile>, <nTop>, <nLeft>, <nBottom>, <nRight>, ; <nStart>, <nCNormal>, <nCHighlight>, <cExitKeys>,   ; <lBrowse>, <nColSkip>, <nRMargin>, <nBuffSize> )
NIL                 FT_FAPPEND( [ < nLines > ] )
lResult             FT_FBOF()
lSuccess            FT_FDELETE( [ < nLines > ] )
lResult             FT_FEOF()
nErrorNo            FT_FERROR()
NIL                 FT_FGOBOT()
NIL                 FT_FGOTO( nLine )
NIL                 FT_FGOTOP()
lSuccess            FT_FINSERT( [ < nLines > ] )
nLastRecordNum      FT_FLASTRE()
cLine               FT_FREADLN()
nRecNo              FT_FRECNO()
nPreviousArea       FT_FSELECT( [ <nNewArea> ] )
nLinesSkipped       FT_FSKIP( [ <nLines> ] )
nHandle | 0         FT_FUSE( [ <cFile> ] [, <nMode> ] )
lSuccess            FT_FWRITELN( < cData >, [ < lInsert > ] )
nBytesWritten       FWRITE(<nHandle>, <cBuffer>, [<nBytes>])
lRet                gZipClose(<nHandle>)
nHandle             gZipOpen(<filename> [,<mode>])
realLen             gZipRead(<nHandle>, <@cBuffer> [,<nLen>])
realLen             gZipWrite(<nHandle>, <cBuffer> [,<nLen>])
<sUnixPath>         MAKEPATH(<sDosPath>)
cString             MEMOREAD(<cFile>)
lSuccess            MEMOWRIT(<cFile>, <cString>)
lError              NETERR([<lNewError>])
NIL                 OUTERR(<exp list>)
NIL                 OUTSTD(<exp list>)
<sPath>             STARTPATH()
<nNewSocket>        TCPACCEPT(<nSock>[, <nTimeout>])
TRUE || FALSE       TCPCLOSE(<nConnection>)
<nConnection>       TCPCONNECT(<sHostName>[, <nPort>][, <nTimeout>])
<nErrNo>            TCPLISTEN(<nPort>[, <nBackLog>])
<nLenBuf>           TCPREAD(<nConnection>, @<sBuffer>, <nLen>[, <nTimeout>])
<nLenBuf>           TCPWRITE(<nConnection>, <sBuffer>, <nLen>[, <nTimeout>])

Description

Function FACCESS()

  FACCESS(<sFileName>, <sMode>) 	--> TRUE || FALSE
 

FACCESS() checks access mode <sMode> for file <sFileName>.

<sMode> is the string in UNIX format "rwx-rwx-rwx" (owner-group-other)

Function FCLOSE()

 FCLOSE(<nHandle>) --> lError

FCLOSE() is a low-level file function that closes binary files and forces the associated DOS buffers to be written to disk. If the operation fails, FCLOSE() returns false (.F.). FERROR() can then be used to determine the reason for the failure. For example, attempting to use FCLOSE() with an invalid handle returns false (.F.), and FERROR() returns DOS error 6, invalid handle. See FERROR() for a complete list of error numbers.

Warning! This function allows low-level access to DOS files and devices. It should be used with extreme care and requires a thorough knowledge of the operating system.

Function FCREATE()

 FCREATE(<cFile>, [<nAttribute>]) --> nHandle

FCREATE() is a low-level file function that either creates a new file or opens and truncates an existing file. If <cFile> does not exist, it is created and opened for writing. If it does exist and can be opened for writing, it is truncated to zero-length. If it cannot be opened for writing, FCREATE() returns -1 and FERROR() returns the appropriate error value.

When FCREATE() successfully creates a new file, the file is left open in compatibility sharing mode and read/write access mode. The file attribute specified by the <nAttribute> argument is applied to the new file when it is closed, allowing writing to a newly created read-only file. For a list of access modes, see FOPEN().

Since a file handle is required in order to identify an open file to other file functions, always assign the return value from FCREATE() to a variable for later use.

Like other file functions, FCREATE() does not use either the DEFAULT or PATH settings for its operation. Instead, it writes to the current DOS directory unless a path is explicitly stated.

Warning! This function allows low-level access to DOS files and devices. It should be used with extreme care and requires a thorough knowledge of the operating system.

Function FERASE()

 FERASE(<cFile>) --> nSuccess

FERASE() is a file function that deletes a specified file from disk. FERASE() is the same as the ERASE command but returns a value and can be specified within an expression. When FERASE() is called, <cFile> is deleted from disk only if found in the current DOS directory or in the directory explicitly specified as part of the file name. Like the other file functions and commands, FERASE() does not use either SET DEFAULT or SET PATH to locate <cFile>.

Warning! Files must be CLOSEd before removing them with FERASE().

Function FERRORSTR()

Function FILE()

 FILE(<cFilespec>) --> lExists

FILE() is an environment function that determines whether any file matching a file specification pattern is found. FILE() searches the specified directory if a path is explicitly specified.

If a path is not specified, FILE() searches the current xClipper default directory and then the xClipper path. In no case is the DOS path searched. Note also that FILE() does not recognize hidden or system files in its search.

Function FILEATTR()

Function FILEATTRS()

  FILEATTRS(<sFileName>) 	--> <sFileAttrs>
 

FILEATTRS() lakes FILEATTR(), but returns string <sFileAttrs>, what contents file attributes.

Function FILEGETSTR()

  FILEGETSTR(<nFileHandle>, <nSize>) 	--> <sFileStr>
 

FILEGETSTR() reads string from opened file. The size result string restrict <CRLF> or <CR>, but no more then <nSize> symbols.

Function FOPEN()

 FOPEN(<cFile>, [<nMode>]) --> nHandle

FOPEN() is a low-level file function that opens an existing binary file for reading and writing, depending on the <nMode> argument. Whenever there is an open error, use FERROR() to return the DOS error number. For example, if the file does not exist, FOPEN() returns -1 and FERROR() returns 2 to indicate that the file was not found. See FERROR() for a complete list of error numbers.

If the specified file is opened successfully, the value returned is the DOS handle for the file. This value is similar to an alias in the database system and is required to identify the open file to other file functions. It is, therefore, important to assign the return value to a variable for later use as in the example below.

Warning! This function allows low-level access to DOS files and devices. It should be used with extreme care and requires a thorough knowledge of the operating system.

<cFile>

is the name of the file to open, including the path if there is one.

<nMode>

is the requested DOS open mode indicating how the opened file is to be accessed. The open mode is composed of elements from the two types of modes described in the tables below. If just the Access Mode is used, the file is opened non-sharable. The default open mode is zero, which indicates non-sharable and read-only.

FOPEN() Access Modes
------------------------------------------------------------------------
Mode    Fileio.ch      Operation
------------------------------------------------------------------------
0       FO_READ        Open for reading (default)
1       FO_WRITE       Open for writing
2       FO_READWRITE   Open for reading or writing
------------------------------------------------------------------------
The Sharing Modes determine how other processes may access the file.
FOPEN() Sharing Modes
------------------------------------------------------------------------
Mode    Fileio.ch      Operation
------------------------------------------------------------------------
0       FO_COMPAT      Compatibility mode (default)
16      FO_EXCLUSIVE   Exclusive use
32      FO_DENYWRITE   Prevent others from writing
48      FO_DENYREAD    Prevent others from reading
64      FO_DENYNONE    Allow others to read or write
64      FO_SHARED      Same as FO_DENYNONE
------------------------------------------------------------------------
The Access Modes in combination (+) with the Sharing modes determine the accessibility of the file in a network environment.

Returns :

FOPEN() returns the file handle of the opened file in the range of zero to 65,535. If an error occurs, FOPEN() returns -1.

See also : FCLOSE() FCREATE() FERROR()

Function FREAD()

 FREAD(<nHandle>, @<cBufferVar>, <nBytes>) --> nBytes

FREAD() is a low-level file function that reads characters from a binary file into an existing character variable. It reads from the file starting at the current DOS file pointer position, advancing the file pointer by the number of bytes read. All characters are read including control, null, and high-order (above CHR(127)) characters.

FREAD() is similar in some respects to both FREADSTR() and FSEEK(). FREADSTR() reads a specified number of bytes from a file up to the next null (CHR(0)) character. FSEEK() moves the file pointer without reading.

If there is an error during the file read, FERROR() returns the DOS error number. See FERROR() for the list of error numbers.

Warning! This function allows low-level access to DOS files and devices. It should be used with extreme care and requires a thorough knowledge of the operating system.

Function FREADSTR()

 FREADSTR(<nHandle>, <nBytes>) --> cString

FREADSTR() is a low-level file function that reads characters from an open binary file beginning with the current DOS 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.

Warning! This function allows low-level access to DOS files and devices. It should be used with extreme care and requires a thorough knowledge of the operating system.

Function FRENAME()

 FRENAME(<cOldFile>, <cNewFile>) --> nSuccess

FRENAME() is a file function that changes the name of a specified file to a new name and is identical to the RENAME command.

When FRENAME() is called, <cOldFile> is renamed only if it is located in the current DOS directory or in the specified path. FRENAME() does not use SET DEFAULT or SET PATH to locate <cOldFile>.

If the source directory is different from the target directory, the file moves to the target directory. In the instance that either <cNewFile> exists or is currently open, FRENAME() fails and returns -1, indicating that it did not perform its designated action. The nature of the error can be determined with FERROR().

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 (.dbt) file must also be renamed. Failure to do so may compromise the integrity of your databases.

Function FSEEK()

 FSEEK(<nHandle>, <nOffset>, [<nOrigin>]) --> nPosition

FSEEK() is a low-level file function that moves the file pointer forward or backward in an open binary file without actually reading the contents of the specified file. The beginning position and offset are specified as function arguments, and the new file position is returned. Regardless of the function arguments specified, the file pointer cannot be moved beyond the beginning or end of file boundaries.

Warning! This function allows low-level access to DOS files and devices. It should be used with extreme care and requires a thorough knowledge of the operating system.

Function FT_DFCLOSE()

 FT_DFCLOSE() --> NIL

Closes the file opened by FT_DFSETUP()

Function FT_DFSETUP()

 FT_DFSETUP( <cInFile>, <nTop>, <nLeft>, <nBottom>, <nRight>, ;
 <nStart>, <nCNormal>, <nCHighlight>, <cExitKeys>,   ;
 <lBrowse>, <nColSkip>, <nRMargin>, <nBuffSize> ) --> nResult

Note: make sure you allocate a buffer large enough to hold enough data for the number of lines that you have in the window. Use the following formula as a guideline:

buffer size = (# of line) + 1 * RMargin

This is the smallest you should make the buffer. For normal use, 4096 bytes is recommended

Function FT_FAPPEND()

  FT_FAPPEND( [ < nLines > ] ) --> NIL
 

This function appends a line of text to the file in the currently selected text file workarea. Text lines are delimited with a CRLF pair. The record pointer is moved to the last appended record.

Multiple lines may be appended with one call to FT_FAPPEND().

A text file "record" is a line of text terminated by a CRLF pair. Each line appended with this function will be empty.

NOTE: Occasionally a text file may contain a non-CRLF terminated line, at the end of the file ("stragglers"). This function assumes these stragglers to be the last line of the file, and begins appending the new lines after this line. In other words, if the last line in the text file is not terminated with a CRLF pair prior to calling FT_FAPPEND(), the function will terminate that last line before appending any new lines.

Function FT_FBOF()

  FT_FBOF() --> lResult
 

This function is similar to the CLIPPER Bof() function.

A text file "record" is a line of text terminated by a CRLF pair.

Function FT_FDELETE()

  FT_FDELETE( [ < nLines > ] ) --> lSuccess
 

This function deletes one or several lines of text from the file in the currently selected text file workarea. Text lines are delimited with a CRLF pair. The record pointer is not moved, unless the deleted lines occur at the end of the file, in which case ^bft_fRecno()^n will equal ^bft_fLastRe()^n and ^bft_fEOF()^n will be set to TRUE.

Function FT_FEOF()

  FT_FEOF() --> lResult
 

This function is similar to the CLIPPER Eof() function.

A text file "record" is a line of text terminated by a CRLF pair.

Function FT_FERROR()

  FT_FERROR() --> nErrorNo
 

This function returns the DOS error code associated with a file operation on the currently selected text file.

Errors could stem from any open, create, read or write operation, among others.

Function FT_FGOBOT()

  FT_FGOBOT() --> NIL
 

This function moves the record pointer to the last record of the file in the currently selected text file workarea.

If a read error occurs ^ft_fError()^n will contain the error code.

A text file "record" is a line of text terminated by a CRLF pair.

Function FT_FGOTO()

  FT_FGOTO( nLine ) --> NIL
 

This function moves the record pointer to a specific record in the file in the currently selected text file workarea. If the record number requested is greater than the number of records in the file, the record pointer will be positioned at the last record.

Internally, the function operates differently depending on how you invoke it. Passing a value for ^b<nLine>^n results in what is effectively a skip operation, which is fairly quick. However if you pass 0 for ^b<nLine>^n, e.g. ft_fGoTo( 0 ), the function internally goes to the top of the file, then skips down the required number of records. Hence if your file is relatively large and the current record is a high number, you may see some delay as ft_fGoTo(0) skips through the file.

A text file "record" is a line of text terminated by a CRLF pair.

Function FT_FGOTOP()

  FT_FGOTOP() --> NIL
 

This function moves the record pointer to the first record in the currently selected text file workarea.

A text file "record" is a line of text terminated by a CRLF pair.

Function FT_FINSERT()

  FT_FINSERT( [ < nLines > ] ) --> lSuccess
 

This function inserts a line of text in the file in the currently selected text file workarea. Text lines are delimited with a CRLF pair.

The record pointer is not moved.

A text file "record" is a line of text terminated by a CRLF pair. Each line inserted with this function will be empty.

Function FT_FLASTRE()

  FT_FLASTRE() --> nLastRecordNum
 

This function returns the number of the last record in a text file.

A text file "record" is a line of text terminated by a CRLF pair.

Function FT_FREADLN()

  FT_FREADLN() --> cLine
 

This function returns a line of text read from the file in the currently selected text file workarea. Text lines are delimited with a CRLF pair. The record pointer is not moved.

Currently the maximum record size is 4096 characters. You may increase the maximum record size by changing the value of ^b#define ^bBUFFSIZE^n in the C source and recompiling, however you should consider the performance implications if you do (all read and writes use this buffer size, including ft_fSkip()'s and ft_fGoto()'s).

If a read error occurs ^ft_fError()^n will contain the error code.

A text file "record" is a line of text terminated by a CRLF pair.

Function FT_FRECNO()

  FT_FRECNO() --> nRecNo
 

This function returns the current record number of the file open in the currently selected text file workarea.

A text file "record" is a line of text terminated by a CRLF pair.

Function FT_FSELECT()

  FT_FSELECT( [ <nNewArea> ] ) --> nPreviousArea
 

This function selects a text file "workarea" from 1 to 10. A file may or may not be open in the selected area.

Passing 0 for ^b<nNewArea>^n selects the next available workarea, similar to Clipper's SELECT 0 command. If no more workareas are available the current workarea is not changed.

Each file is opened in its own "workarea", similar to the concept used by dbf files. As provided, a maximum of 10 files (in 10 workareas) can be opened (assuming there are sufficient file handles available). That number may be increased by modifying the #define TEXT_WORKAREAS in the C source code and recompiling.

All the FT_F*() file functions operate on the file in the currently selected text file workarea.

Text file workareas are separate from and independent of Clipper's database workareas.

Function FT_FSKIP()

  FT_FSKIP( [ <nLines> ] ) --> nLinesSkipped
 

This function moves the text file record pointer, similar to the CLIPPER SKIP command.

Use the return value to determine how many records were actually skipped, for example to write a custom skipper function for TBrowse'g text files.

If a read error occurs ^ft_fError()^n will contain the error code.

A text file "record" is a line of text terminated by a CRLF pair.

Function FT_FUSE()

  FT_FUSE( [ <cFile> ] [, <nMode> ] ) --> nHandle | 0
 

The FT_F*() file functions are for reading text files, that is, files where each line (record) is delimited by a CRLF pair.

Each file is opened in its own "workarea", similar to the concept use by dbf files. As provided, a maximum of 10 files (in 10 workareas) can be opened (assuming there are sufficient file handles available). That number may be increased by modifying the #define TEXT_WORKAREAS in the C source code and recompiling.

Function FT_FWRITELN()

  FT_FWRITELN( < cData >, [ < lInsert > ] ) --> lSuccess
 

This function writes a line of text to the file in the currently selected text file workarea. Text lines are delimited with a CRLF pair. The record pointer is not moved.

The contents of the current record are updated to reflect the new new line written, unless the Insert option is selected.

Writing a null string has the effect of clearing the current line if in overstrike mode, else inserting a new line (same as FT_FINSERT()).

A text file "record" is a line of text terminated by a CRLF pair.

Function FWRITE()

 FWRITE(<nHandle>, <cBuffer>, [<nBytes>]) --> nBytesWritten

FWRITE() is a low-level file function that writes data to an open binary file from a character string buffer. You can either write all or a portion of the buffer contents. Writing begins at the current file position, and the function returns the actual number of bytes written.

If FWRITE() results in an error condition, FERROR() can be used to determine the specific error.

Warning! This function allows low-level access to DOS files and devices. It should be used with extreme care and requires a thorough knowledge of the operating system

Function OUTERR()

 OUTERR(<exp list>) --> NIL

OUTERR() is identical to OUTSTD() except that it writes to the standard error device rather than the standard output device. Output sent to the standard error device bypasses the xClipper console and output devices as well as any DOS redirection. It is typically used to log error messages in a manner that will not interfere with the standard screen or printer output.

Function OUTSTD()

 OUTSTD(<exp list>) --> NIL

OUTSTD() is a simple output function similar to QOUT() except that it writes to the STDOUT device (instead of to the xClipper console output stream). Programs with very simple output requirements (i.e., that perform no full-screen input or output) can use this function to avoid loading the terminal output subsystems. The header file Simplio.ch redefines the ? and ?? commands to use the OUTSTD() function.

Since OUTSTD() sends its output to the standard output device, the output can be redirected using the DOS redirection symbols (>, >, |). This lets you redirect output from a xClipper program to a file or pipe. Refer to your PC/MS-DOS documentation for more information about this operating system facility.