Written by: Oktay Amiry
Date      : March 09, 1993





                 CURDIR.TXT

This file contains instructions about CURDIR.PRG and
GETDIR.EXE programs.  CURDIR() returns the directory name
of a specified drive.  If no drives are specified, CURDIR will
return the directory name of the current drive.  If the specified
drive does not exist or is not accessible, CURDIR() will return
null.

The syntax for CURIDR is:

              CURDIR([<expC>])

where expC is a character representing the drive letter.  The expC
needs to be enclosed in quotes.

Since there is no built-in functionality in dBASE to examine the
existence of directories or to recover from hardware errors, the
CURDIR() is making use of GETDIR.EXE, a stand-alone
executable program written in Borland C++.  The output of
GETDIR is redirected to a temporary file, and is extracted from
there.  CURDIR will automatically erase the temporary file when
done.


Below is the source code for CURDIR.PRG

FUNCTION CURDIR
  PARAMETER lc_drive
  PRIVATE ALL LIKE l*
  IF .NOT. FILE("GETDIR.EXE")
    RETURN "GETDIR.EXE can not be located"
  ENDIF
  lc_comm = IIF(PCOUNT() = 0, "GETDIR", IIF(TYPE("lc_drive") # "C", ;
                   "GETDIR", "GETDIR " + lc_drive))
  ln_val = 1     
  DO WHILE .T.
    lc_file = "curdir" + LTRIM(STR(ln_val)) + ".tmp"
    IF .NOT. FILE(lc_file)
      EXIT
    ELSE
      IF ln_val >= 99
          RETURN "Unable to generate temporary file"
      ENDIF
    ENDIF
    ln_val = ln_val + 1
  ENDDO
  lc_comm = lc_comm + " > " + lc_file
  IF RUN(lc_comm) # 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  lc_dir
* -- EOF



Example:

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

?CURDIR()              D:\
?CURDIR("c")           C:\LANG\BORLANDC\FILES
?CURDIR("A")           null (There was no diskette in A)

An alternative way of getting information, provided that you
merely wish to see the result, is to run GETDIR directly as
follows:

!GETDIR C
RUN GETDIR C
?RUN("GETDIR C")
?RUN("GETDIR A",.T.)   null (There was no diskette in A)

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

GETDIR                 D:\
GETDIR C               C:\LANG\BORLANDC\FILES
GETDIR A:              null (There was no diskette in A)

