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

HB_DirExists

HB_DirExists

Tests for the existence of a directory

Syntax

      HB_DirExists( <cDirName> ) --> <lIsDirectory>

Arguments

<cDirName> : A character string holding the relative or absolute name of a directory.

Return

<lIsDirectory> : .T. (true) when the directory <cDirName> exists, otherwise .F. (false) is returned.

Description

The HB_DirExists() function is used to check if a directory exists that matches the specification <cDirName>.

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

Note

HB_DirExists() 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_DirExists( 'C:\' )                        //  .T.
      ? HB_DirExists( 'C:\*.*' )                     //  .F.
      ? HB_DirExists( 'C:\temp\*.*' )                //  .F.
      ? HB_DirExists( 'C:\temp\*.' )                 //  .F.
      ? HB_DirExists( 'C:\temp\test*.*' )            //  .F.
      ? HB_DirExists( 'C:\temp\test.bat' )           //  .F.
      ? HB_DirExists( 'C:\temp\Dir' )                //  .F.
      ? HB_DirExists( 'C:\temp\Dir*.*' )             //  .F.
      ? HB_DirExists( 'C:\temp\Dir1' )               //  .T.
      ? HB_DirExists( 'C:\temp\Dir1*' )              //  .F.
      ? HB_DirExists( 'C:\temp\Dir2' )               //  .T.
      ? HB_DirExists( 'C:\temp\Dir2*' )              //  .F.
      ? HB_DirExists( 'C:\temp\Dir1\test1.*' )       //  .F.
      ? HB_DirExists( 'C:\temp\Dir1\test1.bat' )     //  .F.
      ? HB_DirExists( 'C:\temp\Dir1\*.bat' )         //  .F.

Seealso

Directory(), File(), IsDir(), IsDirectory(), HB_FileExists(), HB_FNameExists()

HB_FNameNameExt

HB_FNameNameExt

Extracts file name and extension portion of a file specification

Syntax

      HB_FNameNameExt( <cFileSpec>  --> <cFileNameExt>

Arguments

<cFileSpec> : a character string to extract file name and extension

Returns

<cFileNameExt> : file name and extension portion of <cFileSpec>

Note

<cFileSpec> may or may not include an ordinary file name at end. Function returns simply last element of <cFileSpec>

Description

This function is used to extract file name and extension portion of a file specification string. <cFileSpec> doesn’t require include an existing file / path info.

This info can be optained by :

        cFName := ''
        cFNExt := ''
        HB_FNameSplit( cFileSpec, , @cFName, @cFNExt )
        ? cFName + cFNExt
      OR
        ? SUBSTR( cFileSpec, RAT( "\", cFileSpec ) +1 )

Example

      ? HB_FNameNameExt( "c:\temp\NewDirDB" )          // NewDirDB
      ? HB_FNameNameExt( "c:\temp\NewDirDB\test.bat" ) // test

Seealso

HB_FNameDir(), HB_FNameName(), HB_FNameExt(), HB_FNameExtSetDef(), HB_FNameMerge(), HB_FNameSplit()

HB_FNameName

HB_FNameName

Extracts file name portion of a file specification

Syntax

      HB_FNameName( <cFileSpec>  --> <cFileName>

Arguments

<cFileSpec> : a character string to extract file name

Returns

<cFileName> : file name ( without extension ) portion of <cFileSpec>

Note

<cFileSpec> may or may not include an ordinary file name at end. Function returns simply last element of <cFileSpec>

Description

This function is used to extract only file name from a qualified file specification string <cFileSpec> doesn’t require include an existing file / path info. This info can be optained by :

        cFName  := ''
        HB_FNameSplit( cFileSpec, , @cFName )
          ? cFName
      OR
        cNamExt := SUBSTR( cFileSpec, RAT( "\", cFileSpec ) + 1 )
         ? IF( "." $ cNamExt, LEFT( cNamExt,  RAT( ".", cNamExt ) -1 ), cNamExt )

Example

      ? HB_FNameName( "c:\temp\NewDirDB" )          // NewDirDB
      ? HB_FNameName( "c:\temp\NewDirDB\test.bat" ) // test

Seealso

HB_FNameDir(), HB_FNameNameExt(), HB_FNameExt(), HB_FNameExtSetDef(), HB_FNameMerge(), HB_FNameSplit()

<

HB_FNameExtSet

HB_FNameExtSet

Change file extension part of a file specification string

Syntax

      HB_FNameExtSet( <cFileSpec>, <cNewExt>  --> <cNewFileSpec>

Arguments

<cFileSpec> : a file specification string to change file extension part

<cNewExt> : New file extension

Returns

<cNewFileSpec> : File extension changed version of <cFileSpec>

Description

This function is used to change file extension portion of a file specification string.

This can be made by :

        cFPath := ''
        cFName := ''
        HB_FNameSplit( cFileSpec, @cFPath, @cFName )
        ? cFPath + cFName + cNewExt
      OR
        ? IF( "." $ cFileSpec, LEFT( cFileSpec, RAT( ".", cFileSpec ) -1 ), 
            cFileSpec ) + cNewExt

Example

      cFileSpec := "c:\temp\test.prg"
      ? HB_FNameExtSet( cFileSpec, '.ini' )  // c:\temp\test.ini

Seealso

HB_FNameDir(), HB_FNameName(), HB_FNameNameExt(), HB_FNameExt()

HB_FNameExt

HB_FNameExt

Extracts file extension portion of a file specification

Syntax

      HB_FNameExt( <cFileSpec>  --> <cFileExt>

Arguments

<cFileSpec> : a character string to extract file extension

Returns

<cFileExt> : file extension portion of <cFileSpec>

Note

<cFileSpec> may or may not include an ordinary file name at end. Function returns simply very last portion of <cFileSpec>

Description

This function is used to extract path / dir portion of a file specification string. <cFileSpec> doesn’t require include an existing file / path info.

This info can be optained by :

         HB_FNameSplit( cFileSpec, , @cFName, @cFNExt )
         ? cFName + cFNExt
      OR
         IF( "\" $ cFileSpec, SUBSTR( cFileSpec, RAT( ".", cFileSpec ), cFileSpec )

Example

      ? HB_FNameExt( "c:\temp\NewDirDB" )          // ( empty )
      ? HB_FNameExt( "c:\temp\NewDirDB\test.bat" ) // .bat

Seealso

HB_FNameDir(), HB_FNameName(), HB_FNameNameExt(), HB_FNameExtSetDef(), HB_FNameMerge(), HB_FNameSplit()

HB_FNameDir

HB_FNameDir

Extracts path portion of a file specification string

Syntax

      HB_FNameDir( <cFileSpec>  --> <cFilePath>

Arguments

<cFileSpec> : a character string to extract file path

Returns

<cFilePath> : path portion of <cFileSpec>

Note

<cFileSpec> may or may not include an ordinary file name at end. Function returns simply <cFileSpec> except last element <cFilePath> always include trailing OS path separator ( “\” )

Description

This function is used to extract path / dir portion of a full qualified file specification string. <cFileSpec> doesn’t require include an existing file / path info. This info can be optained by :

         HB_FNameSplit( cFileSpec, @cPath )
       OR
          ? IF( "\" $ cFileSpec, LEFT( cFileSpec, RAT( "\", cFileSpec ), 
               cFileSpec

Example

      ? HB_FNameDir( "c:\temp\NewDirDB" )          // c:\temp\
      ? HB_FNameDir( "c:\temp\NewDirDB\test.bat" ) // c:\temp\NewDirDB\

Seealso

HB_FNameName(), HB_FNameNameExt(), HB_FNameExt(), HB_FNameExtSetDef(), HB_FNameMerge(), HB_FNameSplit()

HB_DirCreate

HB_DirCreate

Creates a directory

Syntax

      HB_DirCreate( <cNewDir>) --> <nSuccess>

Arguments

<cNewDir> : the name of the directory to be created, including an optional drive. If you do not specify a drive, the current one is used. The new directory can be specified relative to the current directory, or absolute, including a drive letter followed by a colon.

Return

<nSuccess> : zero on success, -1 if there is an argument error; Otherwise, HB_DirCreate() returns the DOS error code. HB_DirCreate() returns 0 if successful;

Description

HB_DirCreate() creates a specified directory. Note that first you must have sufficient rights to create a directory. To create nested subdirectories, you must create each subdirectory separately, starting from the top-level directory that you want to create (see example below.)

Note

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

Examples

      .  This example assumes that C:\TEST exists and uses HB_DirCreate()
         twice to create a nested subdirectory under it:

      HB_DirCreate("c:\test\one")    // Create top-most one
      nResult := HB_DirCreate("c:\test\one\two")
      IF nResult != 0
         ? "Cannot make directory, DOS error ", nResult
         BREAK
      ENDIF

      You may also use something like this:

      HB_DirCreate( ".\test" )

Seealso

DirChange(), DirName(), DirRemove(), MakeDir(), DirChange()

HB_DirBuild

HB_DirBuild

Creates a directory

Syntax

      HB_DirBuild( <cNewDir>) --> <nSuccess>

Arguments

<cNewDir> : the name of the directory to be created, including an optional drive. If you do not specify a drive, the current one is used. The new directory can be specified relative to the current directory, or absolute, including a drive letter followed by a colon.

Return

<nSuccess> : zero on success, -1 if there is an argument error; Otherwise, HB_DirBuild() returns the DOS error code. HB_DirBuild() returns 0 if successful;

Description

HB_DirBuild() creates a specified directory. Note that first you must have sufficient rights to create a directory. To create nested subdirectories, you must create each subdirectory separately, starting from the top-level directory that you want to create (see example below.)

Note

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

Examples

      .  This example assumes that C:\TEST exists and uses HB_DirBuild()
         twice to create a nested subdirectory under it:

      HB_DirBuild("c:\test\one")    // Create top-most one
      nResult := HB_DirBuild("c:\test\one\two")
      IF nResult != 0
         ? "Cannot make directory, DOS error ", nResult
         BREAK
      ENDIF

      You may also use something like this:

      HB_DirBuild( ".\test" )

Seealso

DirChange(), DirName(), DirRemove(), MakeDir(), DirChange(), HB_DirCreate(), DirMake()