Low-Level File Access

Low-Level File Access Functions

FClose Closes a file opened by low-level access
FCreate Creates a file for low-level access
FErase Erase any file from disk by low-level access
FError Reports the error status of low-level file functions
FOpen Open a file for low-level access
FRead Reads bytes from a file opened with low-level access
FReadStr Reads a string from a file opened with low-level access
FRename Renames a file by low-level access
FSeek Positions the file pointer in a file opened with low-level access
FWrite Writes characters to a file opened with low-level access

Harbour All Functions – F

Fact

Fahrenheit

FClose()
FCount()
FCreate()
FErase()
FError()
FieldBlock()

FieldDeci()

FieldGet()

FieldName()
FieldPos()
FieldPut()

FieldSize()
FieldType()

FieldWBlock()

File()
FLock()

Floor

FOpen()

Found()

FRead()
FReadStr()
FRename()
FSeek()

FToC

FV

FWrite()

FReadStr()

FREADSTR()

Reads a string from a file opened with low-level access

Syntax

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

Arguments

<nHandle> DOS file handle number.

<nBytes> Number of bytes to read.

Returns

<cString> an character expression

Description

This function returns a character string of <nBytes> bytes from a file whose DOS file handle is <nHandle>.

The value of the file handle <nHandle> is obtained from either the FOPEN() or FCREATE() functions.

The value of <nBytes> is the number of bytes to read from the file. The returned string will be the number of characters specified in <nBytes> or the number of bytes read before an end-of-file charac- ter (ASCII 26) is found.

NOTE This function is similar to the FREAD() function, except that it will not read binary characters that may he required as part of a header of a file construct. Characters Such as CHR(0) and CHR(26) may keep this function from performing its intended operation. In this event, the FREAD() function should he used in place of the FREADSTR() function.

Examples

      #include "fileio.ch"
      IF ( nH := FOpen( "x.txt" ) ) != F_ERROR
         cStr := FReadStr( nH, 100 )
         ? cStr
         FClose( nH )
      ENDIF

Compliance

Clipper

Platforms

All (64K)

Files

Library is rtl

Seealso

BIN2I(), BIN2L(), BIN2W(), FERROR(), FREAD(), FSEEK()

C5_FSEEK

 FSEEK()
 Set a binary file pointer to a new position
------------------------------------------------------------------------------
 Syntax

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

 Arguments

     <nHandle> is the file handle obtained from FOPEN(), FCREATE(), or
     predefined by DOS.

     <nOffset> is the number of bytes to move the file pointer from the
     position defined by <nOrigin>.  It can be a positive or negative number.
     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 before
     FSEEK() is executed.  The default value is zero, representing the
     beginning of file.  If <nOrigin> is the end of file, <nOffset> must be
     zero or negative.

     Methods of Moving the File Pointer
     ------------------------------------------------------------------------
     Origin  Fileio.ch      Description
     ------------------------------------------------------------------------
     0       FS_SET         Seek from beginning of file
     1       FS_RELATIVE    Seek from the current pointer position
     2       FS_END         Seek from end of file
     ------------------------------------------------------------------------

 Returns

     FSEEK() returns the new position of the file pointer relative to the
     beginning of file (position 0) as an integer numeric value.  This value
     is without regard to the original position of the file pointer.

 Description

     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.

 Examples

     .  This example uses FSEEK() to determine the length of a file by
        seeking from the end of file.  Then, the file pointer is reset to the
        beginning of file:

        #include "Fileio.ch"
        //
        // Open the file read-only
        IF (nHandle := FOPEN("Temp.txt")) >= 0
           //
           // Get length of the file
           nLength := FSEEK(nHandle, 0, FS_END)
           //
           // Reset file position to beginning of file
           FSEEK(nHandle, 0)
           FCLOSE(nHandle)
        ELSE
           ? "File open error:", FERROR()
        ENDIF

     .  This pseudofunction positions the file pointer at the last
        byte in a binary file:

        #define FileBottom(nHandle);
              (FSEEK(nHandle, 0, FS_END))

     .  This pseudofunction positions the file pointer at the first
        byte in a binary file:

        #define FileTop(nHandle);
              (FSEEK(nHandle, 0))

     .  This pseudofunction reports the current position of the file
        pointer in a specified binary file:

        #define FilePos(nHandle);
              (FSEEK(nHandle, 0, FS_RELATIVE))

 Files   Library is CLIPPER.LIB, header file is Fileio.ch.

See Also: FCLOSE() FCREATE() FERROR() FOPEN() FREAD()



Clipper and Networking

Clipper and Networking

C5 File Management

C5 File Management Commands and Functions

High Level :

ADIR()* :

Fill a series of arrays with directory information

ADIR( [ <cFilespec> ],
    [ <aFilenames> ],
    [ <aSizes> ],
    [ <aDates> ],
    [ <aTimes> ],
    [ <aAttributes> ] ) --> nFiles

CLOSE :

Close a specific set of files

CLOSE [ <idAlias> | ALL | ALTERNATE | DATABASES | FORMAT |INDEXES ]

COPY FILE :

Copy a file to a new file

COPY FILE <xcSourceFile> TO <xcTargetFile> | <xcDevice>

CURDIR() :

Return the current DOS directory

CURDIR( [ <cDrivespec> ] ) --> cDirectory

DELETE FILE :

Remove a file from disk

DELETE FILE | ERASE <xcFile>

DIR* :

Display a listing of files from a specified path

DIR [ <xcFileSpec> ]

        DIRCHANGE() :

      Change the current DOS directory

       DIRCHANGE(<cDir>) --> nSuccess

DIRECTORY() :

Create an array of directory and file information

DIRECTORY( <cDirSpec>, [ <cAttributes> ] ) --> aDirectory

 DIRMAKE()

         Create a directory

        DIRMAKE(<cNewDir>) --> nSuccess

          DIRREMOVE() :

     Remove a directory

       DIRREMOVE(<cDirName>) --> nSuccess

          DISKCHANGE() :

       Change the current DOS disk drive

        DISKCHANGE(<cDrive>) --> lSuccess

          DISKNAME() :

                  Return the current DOS drive

        DISKNAME() --> cDrive

DISKSPACE() :

Return the space available on a specified disk

DISKSPACE( [ <nDrive> ] ) --> nBytes

ERASE :

Remove a file from disk

ERASE | DELETE FILE <xcFile>

FILE() :

Determine if files exist in the default directory or path

FILE( <cFilespec> ) --> lExists

RENAME :

Change the name of a file

RENAME <xcOldFile> TO <xcNewFile>

SET ALTERNATE :

Echo console output to a text file

SET ALTERNATE TO [ <xcFile> [ADDITIVE]]
SET ALTERNATE on | OFF | <xlToggle>

SET DEFAULT :

Set the CA-Clipper default drive and directory

SET DEFAULT TO [ <xcPathspec> ]

SET PATH :

Specify the CA-Clipper search path for opening files

SET PATH TO [ <xcPathspec list> ]

TYPE :

Display the contents of a text file

TYPE <xcFile> [TO PRINTER] [TO FILE <xcOutFile> ]

Low-level :

FCLOSE() :

Close an open binary file and write DOS buffers to disk

FCLOSE( <nHandle> ) --> lError

FCREATE() :

Create and/or truncate a binary file to zero length

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

FERASE() :

Delete a file from disk

FERASE( <cFile> ) --> nSuccess

FERROR() :

Test for errors after a binary file operation

FERROR() --> nErrorCode

FOPEN() :

Open a binary file

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

FREAD() :

Read characters from a binary file into a buffer variable

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

FREADSTR() :

Read characters from a binary file

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

          FRENAME() :

Change the name of a file

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

FSEEK() :

Set a binary file pointer to a new position

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

FWRITE() :

Write to an open binary file

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

HEADER() :

Return the current database file header length

HEADER() --> nBytes