HB_FNameExists

HB_FNameExists

Tests for the existence of a file or a directory

Syntax

      File( <cFileSpec> ) --> lExists

Argument

<cFileSpec> : Exact file name to find

Returns

<lExists> : true (.T.) if the file exists or logical false (.F.)

Description

This function return a logical true (.T.) if the given filename <cFileSpec> exist

Note

HB_FNameExists() don’t accept wildcard characters

Example

      Assuming this directory tree and files exist :

      C:\
         | temp                     D
         + ---- + Dir1              D
                |      doc1.docx    F
                |      test1.bat    F
                |      test1.txt    F
                + Dir2              D
                       doc2.docx    F
                       test2.bat    F
                       test2.txt    F

      ? HB_FNameExists( 'C:\' )                        //  .T.
      ? HB_FNameExists( 'C:\*.*' )                     //  .F.
      ? HB_FNameExists( 'C:\temp\*.*' )                //  .F.
      ? HB_FNameExists( 'C:\temp\*.' )                 //  .F.
      ? HB_FNameExists( 'C:\temp\test*.*' )            //  .F.
      ? HB_FNameExists( 'C:\temp\test.bat' )           //  .T.
      ? HB_FNameExists( 'C:\temp\Dir' )                //  .F.
      ? HB_FNameExists( 'C:\temp\Dir*.*' )             //  .F.
      ? HB_FNameExists( 'C:\temp\Dir1' )               //  .T.
      ? HB_FNameExists( 'C:\temp\Dir1*' )              //  .F.
      ? HB_FNameExists( 'C:\temp\Dir2' )               //  .T.
      ? HB_FNameExists( 'C:\temp\Dir2*' )              //  .F.
      ? HB_FNameExists( 'C:\temp\Dir1\test1.*' )       //  .F.
      ? HB_FNameExists( 'C:\temp\Dir1\test1.bat' )     //  .T.
      ? HB_FNameExists( 'C:\temp\Dir1\*.bat' )         //  .F.

File

Library is rtl

Seealso:

SET DEFAULT, SET PATH, SET(), Directory(), File(), IsDirectory(), IsDir(), HB_FileExists(), HB_DirExists()

HB_FileExists

HB_FileExists

Tests for the existence of a file

Syntax

      HB_FileExists( <cFileSpec> ) --> <lExist>

Arguments

<cFileSpec> : A character string holding the relative or absolute name of a file

Return

<lFileExist> : .T. (true) when the file <cFileSpec> exists, otherwise .F. (false) is returned.

Description

The HB_FileExists() function is used to check if a file exists that matches the specification <lFileExist>.

This is a character string containing the absolute or relative path of a file.

Note

HB_FileExists() is a Harbour level function to check for the existence of a file. This works better than FILE() in most situations, but it doesn’t accept any wildcards.

Example

      Assuming this directory tree and files exist :

      C:\
         | temp                     D
         + ---- + Dir1              D
                |      doc1.docx    F
                |      test1.bat    F
                |      test1.txt    F
                + Dir2              D
                       doc2.docx    F
                       test2.bat    F
                       test2.txt    F

      ? HB_FileExists( 'C:\' )                        //  .F.
      ? HB_FileExists( 'C:\*.*' )                     //  .F.
      ? HB_FileExists( 'C:\temp\*.*' )                //  .F.
      ? HB_FileExists( 'C:\temp\*.' )                 //  .F.
      ? HB_FileExists( 'C:\temp\test*.*' )            //  .F.
      ? HB_FileExists( 'C:\temp\test.bat' )           //  .T.
      ? HB_FileExists( 'C:\temp\Dir' )                //  .F.
      ? HB_FileExists( 'C:\temp\Dir*.*' )             //  .F.
      ? HB_FileExists( 'C:\temp\Dir1' )               //  .F.
      ? HB_FileExists( 'C:\temp\Dir1*' )              //  .F.
      ? HB_FileExists( 'C:\temp\Dir2' )               //  .F.
      ? HB_FileExists( 'C:\temp\Dir2*' )              //  .F.
      ? HB_FileExists( 'C:\temp\Dir1\test1.*' )       //  .F.
      ? HB_FileExists( 'C:\temp\Dir1\test1.bat' )     //  .T.
      ? HB_FileExists( 'C:\temp\Dir1\*.bat' )         //  .F.

Seealso

SET DEFAULT, SET PATH, SET(), Directory(), File(),  IsDirectory(), IsDir(), HB_FNameExists(), HB_DirExists()

TYPE

Display the contents of a text file

Syntax

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

Arguments

<xcFile> is the name of the file, including extension, to be displayed to the screen. This argument may be specified as a literal file name or as a character expression enclosed in parentheses. <xcFile> must be specified with an extension if it has one.

TO PRINTER echoes the display to the printer.

TO FILE <xcOutFile> echoes the display to the specified file. <xcOutFile> may be specified either as a literal file name or as a character expression enclosed in parentheses. If no extension is specified, .txt is added.

Description

TYPE is a console command that displays the contents of a text file to the screen, optionally echoing the display to the printer and/or another text file. To suppress output to the screen while printing or echoing output to a file, SET CONSOLE OFF before the TYPE invocation.

If <xcFile> is specified without a path and/or drive designator, TYPE searches the current DEFAULT directory, and then, the current PATH. If <xcOutFile> is specified without a path and/or drive designator, TYPE creates the file in the current DEFAULT directory.

TYPE performs no special formatting on the listing. There are no special headings or pagination when the output is sent to the printer.

To pause output, use Ctrl-S. Note that you cannot interrupt a listing with Esc.

Examples

      .  This example illustrates the TYPE command:

      TYPE Main.prg TO PRINTER

Seealso

COPY FILE, SET DEFAULT, SET PATH, SET PRINTER

SET PATH

SET PATH

Specifies a search path for opening files

Syntax

      SET PATH TO [<cPath>]

Arguments

<cPath> Search path for files

Description

This command specifies the search path for files required by most commands and functions not found in the current drive and directory. This pertains primarily, but not exclusively, to databases, indexes, and memo files, as well as to memory, labels and reports files. The search hierarchy is: 1 Current drive and directory, 2 The SET DEFAULT path; 3 The SET PATH path.

Examples

      SET PATH TO C:\harbour\test

Compliance

Clipper

Seealso

SET DEFAULT, CurDir(), Set()

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

File()

File

Tests for the existence of file(s)

Syntax

      File( <cFileSpec> ) --> lExists

Argument

<cFileSpec> DOS skeleton (mask) or file name to find

Returns

<lExists> : true (.T.) if the file exists or logical false (.F.)

Description

This function return a logical true (.T.) if the given filename <cFileSpec> exist. DOS skeletons symbols may be used in the filename in <cFileSpec>, as may the drive and/or path name. If a path is not explicitly specified, File() will look for the file in the SET DEFAULT path, then in each SET PATH path, until the file is found or there are no more paths to search. The DOS PATH is never searched and the current drive/directory is only searched if SET DEFAULT is blank.

Example

      Assuming this directory tree and files exist :

      C:\
         | temp                     D
         + ---- + Dir1              D
                |      doc1.docx    F
                |      test1.bat    F
                |      test1.txt    F
                + Dir2              D
                       doc2.docx    F
                       test2.bat    F
                       test2.txt    F

      ? File( 'C:\' )                        //  .F.
      ? File( 'C:\*.*' )                     //  .T.
      ? File( 'C:\temp\*.*' )                //  .T.
      ? File( 'C:\temp\*.' )                 //  .F.
      ? File( 'C:\temp\test*.*' )            //  .T.
      ? File( 'C:\temp\test.bat' )           //  .T.
      ? File( 'C:\temp\Dir' )                //  .F.
      ? File( 'C:\temp\Dir*.*' )             //  .F.
      ? File( 'C:\temp\Dir1' )               //  .F.
      ? File( 'C:\temp\Dir1*' )              //  .F.
      ? File( 'C:\temp\Dir2' )               //  .F.
      ? File( 'C:\temp\Dir2*' )              //  .F.
      ? File( 'C:\temp\Dir1\test1.*' )       //  .T.
      ? File( 'C:\temp\Dir1\test1.bat' )     //  .T.
      ? File( 'C:\temp\Dir1\*.bat' )         //  .T.

Compliance

Cl*pper v5.2

File

Library is rtl

See also:

SET DEFAULT, SET PATH, SET(), IsDirectory(), IsDir(), HB_FileExists(), HB_FNameExists(), HB_DirExists()

__TypeFile()

Template

Function

Name

__TypeFile()

Category

API

Subcategory

Terminal

Oneliner

Show the content of a file on the console and/or printer

Syntax

      __TypeFile( <cFile>,  [<lPrint>] ) --> NIL

Arguments

<cFile> is a name of the file to display. If the file have an extension, it must be specified (there is no default value).

<lPrint> is an optional logical value that specifies whether the output should go only to the screen (.F.) or to both the screen and printer (.T.), the default is (.F.).

Returns

__TypeFile() always return NIL.

Description

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

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

Use SET CONSOLE OFF to suppress screen output.

You can pause the output using Ctrl-S, press any key to resume.

__TypeFile() function is used in the preprocessing of the TYPE command.

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
      __TypeFile( "mytext.dat" )

      // display mytext.dat file on screen and printer
      __TypeFile( "mytext.dat",  .T. )

      // display mytext.dat file on printer only
      SET CONSOLE OFF
      __TypeFile( "mytext.dat",  .T. )
      SET CONSOLE ON

Compliance

Clipper

Files

Library is core

Seealso

COPY FILE, SET DEFAULT, SET PATH, SET PRINTER, TYPE

DIR

DIR

Display listings of files

Syntax

      DIR [<cFileMask>]

Arguments

<cFileMask> File mask to include in the function return. It could contain path and standard wildcard characters as supported by your OS (like * and ?). If <cFileMask> contains no path, then SET DEFAULT path is used to display files in the mask.

Description

If no <cFileMask> is given, __Dir() display information about all *.dbf in the SET DEFAULT path, this information contain: file name, number of records, last update date and the size of each file.

If <cFileMask> is given, __Dir() list all files that match the mask with the following details: Name, Extension, Size, Date.

DIR command is preprocessed into __Dir() function during compile time.

__Dir() is a compatibility function, it is superseded by DIRECTORY() which returns all the information in a multidimensional array.

Examples

      DIR          // information for all DBF files in current directory

      dir   "*.dbf"          // list all DBF file in current directory

      // list all PRG files in Harbour Run-Time library
      // for DOS compatible operating systems
        Dir  "C:\harbour\source\rtl\*.prg"

      // list all files in the public section on a Unix like machine
        Dir  "/pub"

Compliance

Clipper

Platforms

All (LFN)

Seealso

ADIR(), DIRECTORY(), SET DEFAULT, __DIR()*

ADir()

 

ADIR()

Fill pre-defined arrays with file/directory information

Syntax

      ADIR( [<cFileMask>], [<aName>], [<aSize>], [<aDate>],
            [<aTime>], [<aAttr>] ) --> nDirEnries

Arguments

<cFileMask> File mask to include in the function return. It could contain path and standard wildcard characters as supported by your OS (like * and ?). If you omit <cFileMask> or if <cFileMask> contains no path, then the path from SET DEFAULT is used.

<aName> Array to fill with file name of files that meet <cFileMask>. Each element is a Character string and include the file name and extension without the path. The name is the long file name as reported by the OS and not necessarily the 8.3 uppercase name.

<aSize> Array to fill with file size of files that meet <cFileMask>. Each element is a Numeric integer for the file size in Bytes. Directories are always zero in size.

<aDate> Array to fill with file last modification date of files that meet <cFileMask>. Each element is of type Date.

<aTime> Array to fill with file last modification time of files that meet <cFileMask>. Each element is a Character string in the format HH:mm:ss.

<aAttr> Array to fill with attribute of files that meet <cFileMask>. Each element is a Character string, see DIRECTORY() for information about attribute values. If you pass array to <aAttr>, the function is going to return files with normal, hidden, system and directory attributes. If <aAttr> is not specified or with type other than Array, only files with normal attribute would return.

Returns

ADIR() return the number of file entries that meet <cFileMask>

Description

ADIR() return the number of files and/or directories that match a specified skeleton, it also fill a series of given arrays with the name, size, date, time and attribute of those files. The passed arrays should pre-initialized to the proper size, see example below. In order to include hidden, system or directories <aAttr> must be specified.

ADIR() is a compatibility function, it is superseded by DIRECTORY() which returns all the information in a multidimensional array.

Examples

      LOCAL aName, aSize, aDate, aTime, aAttr, nLen, i
      nLen := ADir( "*.jpg" )     // Number of JPG files in this directory
      IF nLen > 0
         aName := Array( nLen )   // make room to store the information
         aSize := Array( nLen )
         aDate := Array( nLen )
         aTime := Array( nLen )
         aAttr := Array( nLen )
         ADir( "*.prg", aName, aSize, aDate, aTime, aAttr )
         FOR i := 1 TO nLen
             ? aName[ i ], aSize[ i ], aDate[ i ], aTime[ i ], aAttr[ i ]
         NEXT
      ELSE
         ? "This directory is clean from smut"
      ENDIF

Compliance

<aName> is going to be filled with long file name and not necessarily the 8.3 uppercase name.

Files

Library is rtl

Seealso

ARRAY(), DIRECTORY(), SET DEFAULT

__Dir()

Template

Function

Name

__Dir()*

Category

API

Subcategory

FileSys

Oneliner

Display listings of files

Syntax

      __Dir( [<cFileMask>] ) --> NIL

Arguments

<cFileMask> File mask to include in the function return. It could contain path and standard wildcard characters as supported by your OS (like * and ?). If <cFileMask> contains no path, then SET  DEFAULT path is used to display files in the mask.

Returns

__Dir() always returns NIL.

Description

If no <cFileMask> is given, __Dir() displays information about all *.dbf in the SET DEFAULT path. This information contains: file name, number of records, last update date and the size of each file.

If <cFileMask> is given, __Dir() list all files that match the mask with the following details: Name, Extension, Size, Date.

DIR command is preprocessed into __Dir() function during compile time.

__Dir() is a compatibility function, it is superseded by Directory() which return all the information in a multidimensional array.

Examples

      __Dir()      // information for all DBF files in current directory

      __Dir( "*.dbf" )         // list all DBF file in current directory

      // list all PRG files in Harbour Run-Time library
      // for MS-DOS compatible operating systems
      __Dir( "src\rtl\*.prg" )

      // list all files in the public section on a Unix like machine
      __Dir( "/pub" )

Compliance

Clipper

Platforms

All(LFN)

Files

Library is core

Seealso

ADir(), Directory(), SET DEFAULT, DIR