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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FOX DOS 2.6 in XP checking exist directory 1

Status
Not open for further replies.

bianliaw

IS-IT--Management
Jan 5, 2004
13
ID
RR

I am using syntax (file("C:\TEMP\NUL")) to check that directory "c:\temp" exist or not, in windows XP didn't work. can anyone help me, please....

TIA
 
How to test and create directories:
From the FNKSHN 1.01 library..
Rob.

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


 
There isn't a way to check for a directory using FILE(), but as well as the previous example, you can use ADIR():
Code:
*... the "D" is the directory attribute
nHowMany = ADIR(aList, "C:\TEMP", "D")  
IF nHowMany = 0
   WAIT WINDOW "Directory doesn't exist" TIMEOUT 2
ENDIF

You can also substitute the following for "D":
[ul]
[li]A for Archive files[/li]
[li]H for Hidden [/li]
[li]R for Read only[/li]
[li]S for System files[/li]
[/ul]

You can then, if you wish, look at the elements of the array 'aList' to see the creation date, size, etc.

-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Another way to check for a directory that doesn't use the DOS NUL file trick, is to try setting the FoxPro default to the directory - if it fails, then you know it doesn't exsist. Here's one routine I used.
Code:
* Usage
IF NOT GOTDIR("C:\RickTemp")
   ** create it or warn missing
ENDIF
*.......
 
FUNCTION GOTDIR
PARAMETERS zcpath
PRIVATE lcsvcurr, lcbasepath, lcdir, llret_val, lcsvonerr
llret_val = .T.

lcsvonerr = ON('ERROR')
ON ERROR DO lhanderr WITH ERROR(), MESSAGE(), MESSAGE(1), PROGRAM(), LINENO()
lcbasepath = ADDBS(zcpath)
lcdir = SUBSTR(lcbasepath, RAT('\', lcbasepath, 2))
lcbasepath = LEFT(lcbasepath, LEN(lcbasepath)-LEN(lcdir)+1)
lcdir = SUBSTR(lcdir, 2, LEN(lcdir)-2)

lcsvcurr = sys(5)+SYS(2003)
SET DEFAULT TO (lcbasepath)
IF llret_val
	lnlength = adir(myjunk,"","D")
	SET DEFAULT TO (lcsvcurr)

	lnfound=ASCAN(myjunk, lcdir)

	RELEASE myjunk
	llret_val = (lnfound > 0)
ENDIF
ON ERROR &lcsvonerr
RETURN llret_val

*!*****************************************************************************
*!
*!       Procedure: lhandler
*!
*!*****************************************************************************

PROCEDURE lhanderr
PARAMETERS zerror, zcmess, zcmess1, zprog, znlineno
PRIVATE    zerror, zcmess, zcmess1, zprog, znlineno

llret_val = .F.   && not valid

RETURN

*
* ADDBS - Add a backslash unless there is one already there.
*
*!*****************************************************************************
*!
*!       Function: ADDBS
*!
*!*****************************************************************************
FUNCTION addbs
* Add a backslash to a path name, if there isn't already one there and uppercase
PARAMETER m.pathname
PRIVATE ALL
m.pathname = ALLTRIM(UPPER(m.pathname))
IF !(RIGHT(m.pathname,1) $ '\:') AND !EMPTY(m.pathname)
   m.pathname = m.pathname + '\'
ENDIF
RETURN m.pathname
Rick
 
Dave Summer's code requires too much knowledge of the file system. Here's my code which only assumes one thing, that root directories always have at least one file or directory. If the entire hard drive is totally empty, I'm not concerned that direxists("D:\") returns .F. Remember that subdirectories always have "." and ".." so they will always return some DIR results even if they are what *you* might call, "empty".

FUNCTION LASTSLASH
PARAMETER XPT1
PRIVATE XPT
XPT=XPT1
IF RIGHT(XPT,1)#"\" THEN
XPT=XPT+"\"
ENDIF
return xpt

function direxist
parameter xdir1
private fl,xdir
if type("XDIR1")="C"
xdir=trim(xdir1)
if len(xdir)>0
if adir(fl,lastslash(xdir)+"*.*","D")>0 then
return .t.
endif
endif
endif
return .f.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top