Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to test if a directory exists and/or create directories

Program Source Code

How to test if a directory exists and/or create directories

by  rob444  Posted    (Edited  )
From the FNKSHN 1.01 library..
Code:
* TEST and create DIRECTORY 
FUNCTION TMKDIR
PARAMETERS _TDIR
PRIVATE err
err = ispath(_TDIR)
if err<>0
 err = makdir(LEFT(_TDIR,LEN(_TDIR)-1))
 if err<>0
   ? _TDIR+' directory doesn't exist and couldn't be made!!!'
 else
   iserr = .f.
 endif  
endif
RETURN  err


* MAKDIR(<directory>)
*
* attempts to make <directory>.  returns .t. if sucessful.
*
function makdir
parameters lcdir
  if type("LCDIR")#"C" or empty(lcdir) 
    return .f.
  endif
  lcdir=trim(lcdir)
  if right(lcdir,1)="\"
    lcdir=substr(lcdir,1,len(lcdir)-1)
  endif
  !md &lcdir
return ispath(lcdir)

* ISPATH(<path>)
*
* Checks if <path> is a valid path.
*
function ispath
parameter lcpath
private lcpath, lftmp1, lnerr, ladir, lcsetdefa, lconerr, lnerr
  lnerr=0
  lcsetdefa=set("DEFAULT")+sys(2003)
  lconerr=on('error')
  on error lnerr=error()
  set defa to (lcpath)
  on error &lconerr
  set defa to (lcsetdefa)
return lnerr


Example call to this function:

=TMKDIR("C:\MyDir")
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top