I tried File("TEMP\*.*") but this didn't work <g>.
TIA
Sent via Deja.com http://www.deja.com/
Before you buy.
What about IF FILE( "C:\MYDIR\." ) // notice the period after the last
slash.
Worth a try.
aDir := Directory( "\temp\*.*" ) // probably make sure the path is
complete...
lIsDir := Valtype( aDir ) == "A" .And. !Empty( aDir )
Try this
FILE(cPath + "\NUL") to check whether the directory cPath exist!
HTH
T.S.LIM
The most universal way (not however under flagship, etc) will be to
create a standalone function called DirExist or use the same named
function from the Overlay or Nanforum toolkits.
Points for build-your-own:
Make sure that the trailing slash is in place or else put it there
Hard code a dummy file name which should not be in place such as
"ad94ptzz.5tr" or create a random name at run-time which will be
best in a multi user environment unless you include part of the
user name somehow
nHandle := fcreate( cPath + cFileName )
if nHandle == -1
/* problem
it is left as an exercise to determine how this will be
reported / handled in your app
did not have rights, subdir did not exist, file by the
same name is being held open by another user, etc
*/
return .f.
endif
// getting here means that cPath does exist
// and the user has rights, etc
fclose( nHandle ) // results in a zero byte-file
inkey(0.1) // disk latency safety
ferase( cPath + cFileName ) // file gone
return .t.
**********************************************************************
*********
FUNCTION DirExist( cDir, cMesg, Alert, aDir )
**********************************************************************
*********
//
IF cDir == NIL
RETURN ( .F. ) // Error!
END
//
cDir := Upper( AllTrim( cDir ))
//
IF ScanDir( cDir, aDir ) != SD_DIR // SD_DIR = 2
//
DEFAULT Alert TO .T., ;
cMesg TO NULL // NULL = ""
//
IF Alert
//
// NOT: BeepAlert() -> Protected!!
Alert( "Error!;" + ;
( cDir ) + "\ sub-directory does not exist!;" + ;
"Do create it by typing the command:-;;" + ;
"MD " + ( cDir ) + ";;" + ;
"- from the DOS Prompt and press RETURN;;" + ;
( cMesg ))
//
ENDIF
//
RETURN ( .F. ) // Error!!
//
ENDIF
//
RETURN ( .T. ) // Found!
**********************************************************************
*********
FUNCTION ScanDir( cDir, aDir )
**********************************************************************
*********
LOCAL nPos := 0 // Protected initialization
//
IF cDir == NIL
RETURN ( SD_NONE ) // SD_NONE = 0
END
//
// File does not find the Directories
IF File( cDir ) // It is only a file - not a directory!!
RETURN ( SD_FILE ) // SD_FILE = 1
END
//
// Assign a default value if none was supplied
// Protected/recommended position!
DEFAULT aDir TO Directory( "*.", "D" ) // Include
.\DIRectories!
//
// cDir directory will NOT be a "file" here as scanning for files
was already done above!!
cDir := AllTrim( cDir )
//
IF Len( aDir ) > 0
nPos := AScan( aDir, { | Elem | Elem[ F_NAME ] == cDir } )
END
//
// nPos > 0 IF cDir was scanned!
RETURN ( If( nPos > 0, SD_DIR, SD_NONE ) )
Please note the File() function does "not" find DIRECTORIES and
"cannot" sense HIDDEN files! Whereas the Directory() function can be
used
to build up a list of Files & Folders. The trick here is to check for
the file first and then
build up an array of files+folders and check for the existence of the
element that
cannot be a file if it exists!
But again, it fails if the file is HIDDEN even if we included hidden
files in the Directory()!
Hope these are simpler and serve your purpose. :~)
Shekar
NJ
======================================================================
==
jon...@my-deja.com wrote in message <8pb409$qg$1...@nnrp1.deja.com>...
function IsDir( cDir )
return ( !file( cDir ) .and. file( cDir + "\nul" ) )
easier, I hope ;-)
regars,
Przemek
>I know that the file() function can be used to determine whether a
>specific file exists, but is there any function that will determine
>whether a directory exists?
>
>I tried File("TEMP\*.*") but this didn't work <g>.
>
>TIA
Hi jon_sk:
The following function will work under almost all OS and circumstances:
FUNCTION ISDIRECTORY( cFile )
LOCAL lRet := .F.
If Empty( cFile ) // No name
RETURN lRet
Endif
cFile := Trim( cFile )
DO WHILE Subs( cFile, -1 ) == "\" // Trim out trailing '\'
cFile := Subs( cFile,1,Len( cFile ) - 1 )
ENDDO
lRet := ASCAN( DIRECTORY( cFile, "D" ), {|x| "D" $ x[F_ATTR] } ) > 0
RETURN lRet
HTH
--
Amilcar Camargo
Sand, S. A.
Guatemala, C. A.
Problem. Always returns .T. on Netware...
--
Phil Barnett mailto:midnight @ the-oasis.net
Oasis WWW http://www.the-oasis.net
FTP Site ftp://ftp.the-oasis.net
Clipper FAQ http://www.the-oasis.net/clipper.html
Harbour Project http://www.Harbour-Project.org
If you are banking on a free software project
getting 'Finished', then you are probably a
poor investor in the first place.
You are right.
Netware clients redirects DOS devices.
probaly function 'file' for
FOO\LPT1
BAR\AUX
FOO_BAR\COM2
BAR_FOO\CLOCK$
...
will retern .T. even the directories (FOO,BAR,...) don't exist
on netware volumes.
regards,
Przemek