DeleteFile

DeleteFile

Deletes an error-tolerant file

Syntax

      DeleteFile(<cFileName>) --> <nErrorCode>

Argument

<cFileName> : file name to delete

Returns

<nErrorCod> : Result of delete operation

          DeleteFile() result Codes
          ------------------------------------------------------------------------
          Code    Symb. constants     Definition
          ------------------------------------------------------------------------
           0      NO_DISK_ERR         No error occurs
          -2      ER_FILE_NOT_FOUND   File not found
          -3      ER_PATH_NOT_FOUND   Path not found
          -5      ER_ACCESS_DENIED    Access denied (e.g., file is read-only)
          ------------------------------------------------------------------------

Description

In contrast to FileDelete(), which permits to specify file groups with wildcards, DeleteFile() only accepts specific file names. However, the function avoids all DOS error messages and returns an error code directly to the calling program. This makes error-tolerant erasures in networks possible.

Note

. You can use a drive designator and path name, but no wildcards.

Examples

      .  How NOT to delete a file in a network environment:

      IF FILE ("TEST.DBF")
         * Is it actually possible to delete the file?
         DELETE FILE TEST.DBF
      ENDIF

      .  This is a better way:

      nStatus  :=  DeleteFile("TEST.DBF")
      IF nStatus == 0
         ? "File deleted."
      ELSE
         IF nStatus == -5
            ? "ACCESS DENIED!"
            ? "File in use elsewhere!"
         ENDIF
      ENDIF

Seealso

FileDelete(), RenameFile()

HB_AParams

HB_AParams

Returns an array containing values of all parameters passed to a function, method or procedure.

Syntax

      HB_AParams() --> <aValues>

Returns

<aValues> : An array with values of all parameters passed

Description

Function HB_AParams() provides a convenient way of collecting all parameters passed to a function, method or procedure with one function call in an array.

Example

      TestApars( 'par1', 'par2', '//par3', 'par4', 'par5' )
      ...
      PROCEDURE TestApars()
         LOCAL aParams := HB_AParams()
         FOR nParamNo := 1 TO LEN( aParams )
             ? nParamNo, aParams[ nParamNo ]
                NEXT
      RETURN

      Result :
      ----------
      1 par1
      2 par2
      3 //par3
      4 par4
      5 par5

See also

PCount(), HB_PValue()

HB_ProgName

HB_ProgName

Returns name and directory of the current Harbour program

Syntax

      HB_ProgName() --> <cProgram>

Returns

<cProgram> : Drive, path and file name of the current .EXE program

Description

This function determines the name and path of the Harbour application in use

Note

This function is synonim of ExeName() and HB_ArgV()

Example

      Determine if the name or path of an EXE file has changed:

      cOrigPath  :=  "C:\DATA\ADDRESS.EXE"
      IF HB_ProgName() <> cOrigPath
         ? "Program name or directory have been changed!"
         QUIT
      ENDIF

Seealso

ExeName(), HB_ArgV(), HB_DirBase()

HB_ArgV

HB_ArgV

Retrieves the value of a command line argument

Syntax

      HB_ArgV( [<nPos>] ) --> cArgValue

Arguments

<nPos> : ordinal position of the command line argument to inspect

Returns

This function returns diffetrent values as character strings depending on [<nPos>] :

         Value         Return
         -----         -------
         NIL           Full file specification ( path + file name and estension of .exe file )
         zero          Same as NIL
         1             First argument in the command line
         2             Second argument in the command line
         ...
         >HB_ArgC()    Null String

Description

HB_ArgV() is used to retrieve the contents of command line arguments passed to an Harbour application when it is started. To ordinal position NIL or zero has a special meaning: it retrieves the full file specification of Harbour application (excecutable).

Example

      // If command line is :  C:\temp>test.exe p1 p2

        ? HB_ArgV()     // C:\temp\test.exe
        ? HB_ArgV( 0)   // C:\temp\test.exe
        ? HB_ArgV( 1 )  // p1
        ? HB_ArgV( 2 )  // p2
        ? HB_ArgV( 3 )  // ( Null String )

Seealso

HB_ArgC(), HB_ArgCheck(), HB_ArgString(), HB_ArgShift(), PCount(),HB_PValue(), HB_AParams()

HB_ArgString

HB_ArgString

Retrieves the vale of an internal switch set on the command line.

Syntax

      HB_ArgString( <cSwitch> ) --> <cValue>

Arguments

<cSwitch> : A string holding the symbolic name of of an internal switch

Returns

If exist <cSwitch> in command line, remain of this switch in the argument, else a null string

Description

There are two kind of internal switches : prefixed and regular. Prefixed internal switches always have two slashes as prefix. This function return value of a prefixed switch.

Example

      // If command line is :  C:\temp>test.exe p1 p2 //p3
      ? HB_ArgString( 'p' ) // 3

Seealso

HB_ArgShift(), HB_ArgC(), HB_ArgCheck(), HB_ArgV(), PCount(), HB_PValue(), HB_AParams()

HB_ArgShift

HB_ArgShift

Updates HB_ARG*() parameter list removing the 1-st one and replacing it by others

Syntax

      HB_ArgShift( [<lProgName>] ) -> NIL

Argument

<lProgName> : If .T. first non internal parameter is moved to hb_argv(0) and all next are shifted.

Returns

NIL

Description

This procedure shifts command line argument each time called and can be used for implementing command line arguments by a loop.

Note

Each time HB_ArgShift() called, return value of HB_ArgC() decremented

Example

      // If command line is :  C:\temp>test.exe p1 p2 //p3 p4 p5
      lProgName := .F.
      nArgC := HB_ArgC()
      FOR nArgNo := 1 TO nArgC // HB_ArgC()     // Each time HB_ArgShift() called, return value of HB_ArgC() decremented
         ? nArgNo, HB_ArgV( 1 )
         HB_ArgShift( lProgName  )
      NEXT
      // Result  :
      // <lProgName>
      // .F.       .T.
      // --------- ---------
      // 1 p1      1 p1
      // 2 p2      2 p2
      // 3 //p3    3 //p3
      // 4 p4      4 //p3
      // 5 p5      5 //p3

Seealso

HB_ArgV(), HB_ArgC(), HB_ArgCheck(), HB_ArgString(), PCount(), HB_PValue(), HB_AParams()

HB_ArgCheck

HB_ArgCheck

Checks existence of an internal switch on the command line

Syntax

      HB_ArgCheck( <cSwitch> ) --> <lExists>

Arguments

<cSwitch> : A character string holding the symbolic name of of an internal switch

Return

.T. (true) when the command line include an internal switch, otherwise .F. (false)

Description

There are two kind of internal switches : prefixed and regular. Prefixed internal switches always have two slashes as prefix. This function tests existence of prefixed switches.

Note

Use function HB_ArgString() to retrieve the value of an internal command line switch

Example

      // If command line is :  C:\temp>test.exe p1 p2 //p3
      ? HB_ArgCheck( 'p' ) // .T.

Seealso

HB_ArgC(), HB_ArgV(), HB_ArgString(), HB_ArgShift(), PCount(), HB_PValue(), HB_AParams()

HB_ArgC

HB_ArgC

Returns the number of command line arguments

Syntax

      HB_ArgC() --> nArgCount

Returns

The function returns the number of command line arguments

Description

When an Harbour application is started, it can be passed arguments from the command line which are received by the initial routine of the application.

HB_ArgC() determines this number of arguments. The contents of command line arguments can be retrieved with function HB_ArgV().

Example

      // If command line is :  C:\temp>test.exe p1 p2
      ? HB_ArgC() // 2

Seealso

HB_ArgV(), HB_ArgCheck(), HB_ArgString(), HB_ArgShift(), PCount(), HB_PValue(), HB_AParams()

IsDirectory

IsDirectory

Tests for the existence of directories

Syntax

      IsDirectory( <cDirName> ) --> <lIsDirectory>

Arguments

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

Return

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

Description

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

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

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

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

Seealso

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

IsDir

IsDir

Tests for the existence of directories

Syntax

      IsDir( <cDirName> ) --> <lIsDirectory>

Arguments

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

Return

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

Description

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

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

Note

IsDir() is name abreviated version of IsDirectory()

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

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

Seealso

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