DirChange()

DIRCHANGE()

Changes the directory

Syntax

      DIRCHANGE( <cDirectory> ) --> nError

Arguments

<cDirectory> The name of the directory you want do change into.

Returns

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

Description

This function attempt to change the current directory to the one specified in <cDirectory>. If this function fails, it will return the last OS error code number. See FERROR() function for the description of the error.

Examples

      IF DirChange( "\temp" ) == 0
         ? "Change to diretory was successfull"
      ENDIF

Tests

      See examples

Compliance

This function is CA-Cl*pper 5.3 compliant

Platforms

All

Files

Library is rtl

Seealso

MAKEDIR(), DIRREMOVE(), ISDISK(), DISKCHANGE(), DISKNAME(), FERROR()

C5_DIRCHANGE

 DIRCHANGE()
 Change the current DOS directory
------------------------------------------------------------------------------
 Syntax

     DIRCHANGE(<cDir>) --> nSuccess

 Arguments

     <cDir> is the name of the directory to change to, including the
     drive.

 Returns

     DIRCHANGE() returns 0 if successful; -1 if there is an argument error.
     Otherwise, DIRCHANGE() returns the DOS error code.

 Description

     DIRCHANGE() changes the current DOS directory.  This function may also
     be used to determine whether or not a directory exists.

 Examples

     .  The following example attempts to change to the "c:\dos"
        directory.  If it is unsuccessful, an error message is displayed.

        nResult :=  DIRCHANGE("c:\dos")

        IF nResult != 0
           ? "Cannot change directory. "
           DO CASE
              CASE nResult == 3
                 ?? "Directory does not exist."
              CASE nResult == 5
                 ?? "Access to directory denied."
           END
           BREAK
        ENDIF

       You may also use something like this:

        DIRCHANGE( "..\..\test" )

 Files   Library is EXTEND.LIB.

See Also: CURDIR(), DIR*, DIRMAKE(), DIRREMOVE(), DIRCHANGE()

CT_DIRCHANGE

DIRCHANGE()
 Changes the current directory
------------------------------------------------------------------------------
 Syntax

     DIRCHANGE(<cDirectory>) --> nErrorCode

 Argument

     <cDirectory>  Designates the path of the directory that is changed.

 Returns

     DIRCHANGE() returns a 0 when it successfully changes the directory;
     otherwise, an error code is passed.  The codes are defined as follows:

     Table 7-2:  DIRCHANGE() Error Codes
     ------------------------------------------------------------------------
     Code    Symb. constants     Definition
     ------------------------------------------------------------------------
      0      NO_DISK_ERR         No error occurred
     -2      ER_FILE_NOT_FOUND   File not found
     -3      ER_PATH_NOT_FOUND   Path not found
     -5      ER_ACCESS_DENIED    Access denied (e.g., in network)
     ------------------------------------------------------------------------

     DIRCHANGE() changes the current subdirectory or determines if a
     directory exists.  This allows DOS error messages to be intercepted.
     (See also DIRMAKE()).

 Note

     .  <cDirectory> may contain a drive designator and a path.
        Wildcards are not allowed.

 Example

     Change to the "\DATA" directory:

     IF DIRCHANGE("\DATA") == 0
        ? "Current directory is now:  " + DIRNAME()
     ENDIF

See Also: DIRMAKE() DIRNAME() DIRREMOVE()

 

Tools — Disk Utilities

Introduction Disk Utilities
DELETEFILE() Deletes an error-tolerant file
DIRCHANGE()  Changes the current directory
DIRMAKE()    Creates a directory
DIRNAME()    Determines the name of the current directory
DIRREMOVE()  Removes a directory
DISKCHANGE() Changes the current disk drive
DISKCHECK()  Creates a checksum for a disk
DISKFORMAT() Formats disks, controlled through a UDF
DISKFREE()   Determines the space available on a floppy or hard disk
DISKNAME()   Determines the drive designator for the current drive
DISKREADY()  Tests to see if a disk drive is ready
DISKREADYW() Queries whether you can write to a drive
DISKSPEED()  Determines a comparison value for the drive speed
DISKSTAT()   Determines the status of a drive.
DISKTOTAL()  Determines the total capacity of a floppy or hard disk
DISKTYPE()   Determines the type of data carrier
DRIVETYPE()  Determines the drive type
FILEAPPEND() Appends data to a file
FILEATTR()   Determines a file's attributes
FILECCLOSE() Closes a file after backup mode
FILECCONT()  Copies sections of a file in backup mode
FILECDATI()  Determines which date the target file contains with FILECOPY()
FILECHECK()  Calculates/computes/determines a checksum for a file
FILECOPEN()  Tests to see if the file is still open in the backup mode
FILECOPY()   Copies files normally or in backup mode
FILEDATE()   Determines the file date
FILEDELETE() Deletes file(s) by name and attribute
FILEMOVE()   Moves files to another directory
FILESEEK()   Searches for files by name and attribute
FILESIZE()   Determines the size of a file
FILESTR()    Reads a portion of a file into a string
FILETIME()   Determines a file's time
FILEVALID()  Tests whether a string has a valid file name
FLOPPYTYPE() Determines the exact type of floppy drive
GETSHARE()   Determines the file open (share) mode
NUMDISKF()   Determines the number of installed disk drives
NUMDISKH()   Determines the number of hard disks
NUMDISKL()   Determines the number of available logical drives
RENAMEFILE() Fault tolerant renaming of a file.
RESTFSEEK()  Restores the FILESEEK environment
SAVEFSEEK()  Saves the current FILESEEK environment
SETFATTR()   Sets a file's attributes
SETFCREATE() Default attribute for creating with CA-Clipper Tools functions
SETFDATI()   Sets the date and time of a file
SETSHARE()   Sets default opening mode for CA-Clipper Tools file functions
STRFILE()    Writes a string to a file
TEMPFILE()   Creates a file for temporary use
TRUENAME()   Standardizes the path designation
VOLSERIAL()  Determines the DOS disk serial number
VOLUME()     Establishes a volume label for a floppy or hard disk

DIRCHANGE() Function

DIRCHANGE() Function Sample

/*
DIRCHANGE()

    Change the current DOS directory

Syntax :

DIRCHANGE( <cDir> ) –> nSuccess

Arguments :

<cDir> is the name of the directory to change to, including the drive.

Returns :

   DIRCHANGE() returns 0 if successful; -1 if there is an argument error. Otherwise, DIRCHANGE() returns the DOS error code.

Description :

  DIRCHANGE() changes the current DOS directory. This function may also be used to determine whether or not a directory exists.

Examples :

  The following example attempts to change to the “c:\dos” directory. If it is unsuccessful, an error message is displayed.

 nResult := DIRCHANGE("c:\dos")
 IF nResult != 0
    ? "Cannot change directory. "
    DO CASE
      CASE nResult == 3
         ?? "Directory does not exist."
      CASE nResult == 5
         ?? "Access to directory denied."
    ENDCASE
    BREAK
 ENDIF

 You may also use something like this:
 DIRCHANGE( "..\..\test" )

 Remarks :

    If <cDir> includs drive specifier, DIRCHANGE() also changes the current drive.

*/

PROC DirChTest()
    LOCAL cDirToChange := "c:\harbour"

    LOCAL cCurDrive := DISKNAME()

    LOCAL nResult

    ? "Current Drive is :", cCurDrive

    nResult := DIRCHANGE( cDirToChange )
    IF nResult = 0
       cCurDrive := DISKNAME()
       ? "Current directory of drive", cCurDrive, "changed to :", CURDIR()
    ELSE
       ? "Cannot change directory to", cDirToChange, ": "
       DO CASE
          CASE nResult = 2
             ?? "File does not exist."
          CASE nResult = 3
             ?? "Directory does not exist."
          CASE nResult = 5
             ?? "Access to directory denied."
          CASE nResult = 15
             ?? "Invalid Drive was specified."
          CASE nResult = 21
             ?? "Drive not ready." 
          OTHE 
             ?? "Unknown error !", nResult
       ENDCASE
    ENDIF

    // Inspect dir existence :
    cDirToChange := "C:\TEMP"
    ? DISKNAME() + ":\" + CURDIR()
    ? cDirToChange, "directory is", IF( IsThisADir( cDirToChange ),;
                                        "", "not" ), "exists." 
    ? DISKNAME() + ":\" + CURDIR()
    ?
    WAIT "End of DIRCHANGE.PRG"

RETU // DirChTest()

/*
 Using DIRCHANGE() function to determine whether or not a directory exists.
*/

FUNC IsThisADir( cDirSpec )
   LOCAL cCurrent := DISKNAME() + "\" + CURDIR(),;
         lRetval := .F.

   IF !EMPTY( cDirSpec )
      lRetval := ( DIRCHANGE( cDirSpec ) = 0 )
      DIRCHANGE( cCurrent )
   ENDIF

RETU lRetval // IsThisADir()

Directory List

Reinvention of wheel ?

Not quite …

Main difference is allowing file(s) and folder(s) selection together.

Another difference is implementing of <lNoChangeDir> parameter. Unlike GetFile(), GetDIRList() uses this value  for allowing change directory ability to user.

Furthermore sorting grid columns by three (not two) ways, GetVolumLabel(), List2Arry() and Arry2List()  functions may be useful.

Also, test program ( TestGDL.prg ) may be a sample for .fmg based application.

Download here ( source only ).