TYPE

TYPE

Show the content of a file on the console, printer or file

Syntax

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

Arguments

<xcFile> is a name of the file to display. If the file have an extension, it must be specified (there is no default value). It can be specified as literal file name or as a character expression enclosed in parentheses.

TO PRINTER is an optional keyword that specifies that the output should go to both the screen and printer.

TO FILE <xcDestFile> copy the source <xcFile> also to a file. If no extension is given (.txt) is added to the output file name. <xcDestFile> can be specified as literal file name or as a character expression enclosed in parentheses.

Description

TYPE command type the content of a text file on the screen with an option to send this information also to the printer or to an alternate file. The file is displayed as is without any headings or formatting.

If <xcFile> contain no path, TYPE try to find the file first in the SET DEFAULT directory and then in search all of the SET PATH directories. If <xcFile> can not be found a run-time error occur.

If <xcDestFile> contain no path it is created in the SET DEFAULT directory.

Use SET CONSOLE OFF to suppress screen output. You can pause the output using Ctrl-S, press any key to resume.

Examples

      The following examples assume a file name mytext.dat exist in all
      specified paths,  a run-time error would displayed if it does not

      // display mytext.dat file on screen
      TYPE mytext.dat

      // display mytext.dat file on screen and printer
      TYPE mytext.dat TO PRINTER

      // display mytext.dat file on printer only
      SET CONSOLE OFF
      TYPE mytext.dat TO PRINTER
      SET CONSOLE ON

      // display mytext.dat file on screen and into a file myreport.txt
      TYPE mytext.dat TO FILE MyReport

Compliance

Clipper

Seealso

COPY FILE, SET DEFAULT, SET PATH, SET PRINTER, __TypeFile()

RENAME

RENAME

Changes the name of a specified file

Syntax

      RENAME <cOldFile> TO <cNewFile>

Arguments

<cOldFile> Old filename

<cNewFile> New Filename

Description

This command changes the name of <cOldFile> to <cNewFile>. Both <cOldFile> and <cNewFile> must include a file extension. This command if not affected by the SET PATH TO or SET DEFAULT TO commands; drive and directory designates must be specified if either file is in a directory other then the default drive and directory.

If <cNewFile> id currently open or if it previously exists, this command will not perform the desired operation.

Examples

      RENAME hello.txt TO hello.old

Compliance

Clipper

Files

Library is rtl

Seealso

CURDIR(), ERASE, FILE(), FERASE(), FRENAME()

MakeDir

MAKEDIR()

Create a new directory

Syntax

      MAKEDIR( <cDirectory> ) --> nError

Arguments

<cDirectory> The name of the directory you want to create.

Returns

<nError> 0 if directory was successfully created, otherwise the number of the last error.

Description

This function attempt to create a new directory with the name contained in <cDirectory>. If this function fails, it will return the last OS error code number. See FERROR() function for the description of the error

Note

     MakeDir() is equivalent to DirMake(), HB_DirCreate() and HB_DirBuild()

Examples

      cDir := "temp"
      IF MakeDir( cDir ) == 0
         ? "Directory", cDir, "successfully created"
      ENDIF

Tests

      See examples

Compliance

This function is CA-Cl*pper 5.3 compliant

Platforms

All

Files

Library is rtl

Seealso

DIRCHANGE(), DIRREMOVE(), ISDISK(), DISKCHANGE(), DISKNAME(), FERROR(), DirMake(), HB_DirCreate(), HB_DirBuild()

IsDisk()

ISDISK()

Verify if a drive is ready

Syntax

      ISDISK( <cDrive> ) --> lSuccess

Arguments

<cDrive> An valid Drive letter

Returns

<lSuccess> .T. is the drive is ready, otherwise .F.

Description

This function attempts to access a drive. If the access to the drive was successfull, it will return true (.T.), otherwise false(.F.). This function is usefull for backup function, so you can determine if the drive that will receive the backup data is ready or not.

Examples

      IF IsDisk( "A" )
         ? "Drive is ready "
      ENDIF

Tests

      See Examples

Compliance

This function is CA-Cl*pper 5.3 compliant

Platforms

All

Files

Library is rtl

Seealso

DIRCHANGE(), MAKEDIR(), DIRREMOVE(), DISKCHANGE(), DISKNAME()

HB_FEof()

HB_FEOF()

Check for end-of-file.

Syntax

      HB_FEOF( <nHandle> ) --> lIsEof

Arguments

<nHandle> The handle of an open file.

Returns

<lIsEof> .T. if the file handle is at end-of-file, otherwise .F.

Description

This function checks an open file handle to see if it is at EOF.

If the file handle is missing, not numeric, or not open, then this function returns .T. and sets the value returned by FERROR() to -1 (FS_ERROR) or a C-compiler dependent errno value (EBADF or EINVAL).

Examples

      nH := FOpen( "file.txt" )
      ? FReadStr( nH, 80 )
      IF hb_FEof( nH )
         ? "End-of-file reached."
      ELSE
         ? FReadStr( nH, 80 )
      ENDIF

Compliance

Harbour

Files

Library is rtl

Seealso

FERROR()

FWrite()

FWRITE()

Writes characters to a file opened with low-level access

Syntax

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

Arguments

<nHandle> DOS file handle number.

<cBuffer> Character expression to be written.

<nBytes> The number of bytes to write.

Returns

<nBytesWritten> the number of bytes successfully written.

Description

This function writes the contents of <cBuffer> to the file designated by its file handle <nHandle>. If used, <nBytes> is the number of bytes in <cBuffer> to write.

The returned value is the number of bytes successfully written to the DOS file. If the returned value is 0, an error has occurred (unless this is intended). A successful write occurs when the number returned by FWRITE() is equal to either LEN( <cBuffer>) or <nBytes>.

The value of <cBuffer> is the string or variable to be written to the open DOS file <nHandle>.

The value of <nBytes> is the number of bytes to write out to the file. The disk write begins with the current file position in <nHandle>. If this variable is not used, the entire contents of <cBuffer> is written to the file. To truncate a file, a call of FWRITE( nHandle, “”, 0 ) is needed.

Examples

      nHandle := FCreate( "x.txt" )
      FOR X := 1 TO 10
         FWrite( nHandle, Str( x ) )
      NEXT
      FClose( nHandle )

Compliance

Clipper

Platforms

All (64K)

Files

Library is rtl

Seealso

FCLOSE(), FCREATE(), FERROR(), FOPEN(), I2BIN(), L2BIN()

FSeek()

FSEEK()

Positions the file pointer in a file opened with low-level access

Syntax

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

Arguments

<nHandle> DOS file handle.

<nOffset> The number of bytes to move.

<nOrigin> The relative position in the file.

Returns

<nPosition> the current position relative to begin-of-file

Description

This function sets the file pointer in the file whose DOS file handle is <nHandle> and moves the file pointer by <expN2> bytes from the file position designated by <nOrigin>. The returned value is the relative position of the file pointer to the beginning-of-file marker once the operation has been completed.

<nHandle> is the file handle number. It is obtained from the FOPEN() or FCREATE() function.

The value of <nOffSet> is the number of bytes to move the file pointer from the position determined by <nOrigin>. The value of <nOffset> may be a negative number, suggesting backward movement.

The value of <nOrigin> designates the starting point from which the file pointer should he moved, as shown in the following table:

       <nOrigin>   fileio.ch     File position
       ----------- ------------- ---------------------------------- 
       0           FS_SET        Beginning of file
       1           FS_RELATIVE   Current file pointer position
       2           FS_END        End of file

If a value is not provided for <nOrigin>, it defaults to 0 and moves the file pointer from the beginning of the file.

Examples

      // here is a function that read one text line from an open file

      // nH = file handle obtained from FOpen()
      // cB = a string buffer passed-by-reference to hold the result
      // nMaxLine = maximum number of bytes to read

      FUNCTION FREADln( nH, cB, nMaxLine )
         LOCAL cLine, nSavePos, nEol, nNumRead
         cLine := Space( nMaxLine )
         cB := ""
         nSavePos := FSeek( nH, 0, FS_RELATIVE )
         nNumRead := FRead( nH, @cLine, nMaxLine )
         IF ( nEol := At( hb_eol(), SubStr( cLine, 1, nNumRead ) ) ) == 0
            cB := cLine
         ELSE
            cB := SubStr( cLine, 1, nEol - 1 )
            FSEEK( nH, nSavePos + nEol + 1, FS_SET )
         ENDIF
         RETURN nNumRead != 0

Compliance

Clipper

Files

Library is rtl Header is fileio.ch

Seealso

FCREATE(), FERROR(), FOPEN(), FREAD(), FREADSTR(), FWRITE()

FRename()

FRENAME()

Renames a file by low-level access

Syntax

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

Arguments

<cOldFile> Old filename to be changed

<cNewFile> New filename

Returns

<nSuccess> If successful, a 0 will be returned otherwise, a -1 will be returned.

Description

This function renames the specified file <cOldFile> to <cNewFile>. A filename and/or directory name may be specified for either parameter. However, if a path is supplied as part of <cNewFile> and this path is different from either the path specified in <cOldFile> or (if none is used) the current drive and directory, the function will not execute successfully.

Neither parameter is subject to the control of the SET PATH TO or SET DEFAULT TO commands. In attempting to locate the file to be renamed, this function will search the default drive and directory or the drive and path specified in <cOldFile>. It will not search directories named by the SET PATH TO and SET DEFAULT TO commands or by the DOS PATH statement.

If the file specified in <cNewFile> exists or the file is open, the function will be unable to rename the file. If the function is unable to complete its operation, it will return a value of -1. If it is able to rename the file, the return value for the function will be 0. A call to FERROR() function will give additional infor- mation about any error found.

Examples

      #include "fileio.ch"
      nResult := FRename( "x.txt", "x1.txt" )
      IF nResult == F_ERROR
         ? "File could not be renamed."
      ENDIF

Compliance

Clipper

Files

Library is rtl

Seealso

ERASE, FERASE(), FERROR(), FILE(), RENAME

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()

FRead()

FREAD()

Reads bytes from a file opened by low-level access

Syntax

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

Arguments

<nHandle> Dos file handle

<cBuffer> Character expression passed by reference.

<nBytes> Number of bytes to read.

Returns

<nBytes> the number of bytes successfully read from the file. <nHandle>

Description

This function reads the characters from a file whose file handle is <nHandle> into a character memory variable expressed as <cBuffer>. The function returns the number of bytes successfully read into <cBuffer>.

The value of <nHandle> is obtained from either a call to the FOPEN() or the FCREATE() function.

The <cBuffer> expression is passed by reference and must be defined before this function is called. It also must be at least the same length as <nBytes>.

<nBytes> is the number of bytes to read, starting at the current file pointer position. If this function is successful in reading the characters from the file, the length of <cBuffer> or the number of bytes specified in <nBytes> will be the value returned. The current file pointer advances the number of bytes read with each successive read. The return value is the number of bytes successfully read from the file. If a 0 is returned, or if the number of bytes read matches neither the length of <cBuffer> nor the specified value in <nBytes> an end-of-file condition has been reached.

Examples

      #include "fileio.ch"
      cBuffer := Space( 500 )
      IF ( nH := FOpen( "x.txt" ) ) == F_ERROR
         FRead( nH, @cBuffer, 500 )
         ? cbuffer
      ENDIF
      FClose( nH )

Compliance

Clipper

Platforms

All (64K)

Files

Library is rtl

Seealso

BIN2I(), BIN2L(), BIN2W(), FERROR(), FWRITE()