07-18-2003, 06:28 AM
I am using Visual Basic V6 and I am trying to determine if a directory exists. I have tried a couple of routines I found on the web, but they aren't working.
All I want to do is print "Directory Exists" if it does exist and "Directory Doesn't Exist" if it doesn't.
Can anyone help out?
07-18-2003, 06:32 AM
There are a variety of ways of solving this.
Public Function CheckFileExists(FileName As String) As Boolean
On Error GoTo Error
CheckFileExists = False
If Dir(FileName, vbDirectory) <> "" Then
CheckFileExists = True
or you could use the getattr function to get more information as to wether the filename is a dir/file/ etc..
07-18-2003, 06:42 AM
The FileSystemObject has got a function to determine the existance of a folder. I can't remember the function's name and I'm not at home so I can't check at the moment, someone else will probably be able to fill you in on the details...
07-18-2003, 06:46 AM
To check if a file exists:
FileExist = Len(Dir$(strPath)) <> 0
To check if a Directory exists:
Function DirExist(ByVal DirPath As String) As Boolean
On Error Resume Next
'The above line is only required on Win NT4, and 2K. Remove on Win9x
DirExist = Len(Dir$(DirPath, vbDirectory)) <> 0
To check to see if strFile is a directory or not:
If (GetAttr(strPath & “\” & strFile) AND vbDirectory) = vbDirectory then
' it’s a directory, not a file
07-18-2003, 06:50 AM
Here's for you immo :
fs.FolderExists(path) returns a bool
07-18-2003, 09:41 AM
Thanks :p I should know that really, I was using the FSO most of yesterday evening..