Written by: Oktay Amiry
Date      : March 09, 1993






                                ISDIR.TXT

This file contains information about ISDIR.PRG and
ISDIRECT.EXE programs. ISDIR() is a UDF that can be used
within dBASE to determine if a specified directory exists. The
return value of ISDIR() is logical, where .T. denotes an existent
directory, and .F. denotes a non-existent directory. Note that if the
specified drive is for any reason unavailable, ISDIR() will also
return a false value.

The syntax for ISDIR is as follows:

             ISDIR(<expC1>[,<expC2>])

where

      expC1      is a required character type parameter,
                 representing the directory name.

      expC2      is an optional character type parameter,
                 representing the access permission to the
                 specified directory. The program checks for
                 DOS permissions, and may incorrectly
                 detect permission on networks with
                 proprietary priviledge schemes. 

                 expC2 can denote the following access
                 permissions:

                 R            Read Permission
                 W            Write Permission
                 RW or WR     Read and Write Permission


Since dBASE does not have the inherent ability to check the
existence of directories, ISDIR() is in reality calling
ISDIRECT.EXE, a stand-alone executable written in Borland
C++, to perform the job. The result of ISDIRECT.EXE program
is being redirected and extracted from a temporary file. The
temporary file is automatically erased when the ISDIR() completes
its task.

Below is the source code for ISDIR.PRG:

FUNCTION ISDIR
   PARAMETER lc_dir, lc_access
   PRIVATE ALL LIKE l*
   IF .NOT. FILE("ISDIRECT.EXE")
     RETURN "ISDIRECT.EXE can not be located"
   ENDIF
   DO CASE
     CASE PCOUNT() = 0
       RETURN "Usage: ISDIR(<directory>[,<access permission>])"
     CASE TYPE("lc_dir") # "C" .OR. ISBLANK(lc_dir)
       RETURN "Usage: ISDIR(<directory>[,<access permission>])"
     CASE PCOUNT() > 1 .AND. TYPE("lc_access") # "C"
       RETURN "Usage: ISDIR(<directory>[,<access permission>])"
   ENDCASE
   lc_comm = IIF(PCOUNT() = 1, "ISDIRECT " + lc_dir, ;
                 "ISDIRECT " + lc_dir + " "  + lc_access )
   ln_val = 1
   DO WHILE .T.
     lc_file = "isdir" + LTRIM(STR(ln_val)) + ".tmp"
     IF .NOT. FILE(lc_file)
       EXIT
     ELSE
       IF ln_val >= 999
         RETURN "Unable to generate temporary file"
       ENDIF
     ENDIF
     ln_val = ln_val + 1
   ENDDO
     
   lc_comm = lc_comm + " > " + lc_file
   ln_run = RUN(lc_comm)
   IF ln_run # 0
     RETURN -1
   ELSE
     ln_handle = FOPEN((lc_file),"R")
     lc_dir    = FGETS(ln_handle)
     ll_close  = FCLOSE(ln_handle)
     ERASE (lc_file)
   ENDIF
RETURN  IIF( lc_dir = "T", .T.,IIF( lc_dir = "F", .F.,""))
* -- EOF



Tip:

Due to the hierarchial file structure of DOS systems, all drives
have a root directory.  I considered it redundant to create a
separate program such as ISDRIVE to see if a drive exists or is
available.  Rather, by checking to see if a root directory of a drive
exists, you can establish the same task.  Therefore to see if drive
A is ready, you can run ?ISDIR("A:\").  If the reply is .T., the
drive is ready, else, the drive is not ready.



Example:

Below is the result of running this function on my system, while
I was on the root directory of the D drive. 

?ISDIR("c:\DBASE")     .T.          
?ISDIR("A")            .F. (There was no diskette in A)
?ISDIR("C:\FOXPRO")    .F. (Directory does not exist)

An alternative and quicker way of getting information, provided
that you merely wish to see the result, is to run ISDIRECT
directly from dBASE as follows:

!ISDIRECT C:\DBASE
RUN ISDIRECT C:\DBASE R
?RUN("ISDIRECT C:\DBASE R")
?RUN("ISDIRECT C:\DBASE RW",.T.) 

As was mentioned, ISDIRECT.EXE can be run directly from
DOS.  Below are examples of using ISDIRECT in DOS.

ISDIRECT  D:\
ISDIRECT  C:\LANG\BORLANDC\FILES RW
ISDIRECT  A: W
