tags:

views:

350

answers:

2

How to find if the directory is available or not?

Using VB 6.0

databasetext = network path available

If Len(Dir(databasetext)) = False Then
MsgBox "Database Path Not Available"
End if

I am selecting the file from the network path, if the network path is not available, it showing error "bad file name or number"

How to solve this problem?

Need VB 6 code Help

+2  A: 

I use PathIsDirectory from Shlwapi.dll. Here is some VB6 code:

Private Declare Function PathIsDirectory Lib "Shlwapi" _
    Alias "PathIsDirectoryW" (ByVal lpszPath As Long) As Long

Function DirExists(ByVal sDirName As String) As Boolean   
  'NB The shlwapi.dll is built into Windows 2000 and 98 and later:  ' 
  '   it comes withInternet Explorer 4 on NT 4 and 95. '  
  'NB Calling "Wide" (Unicode) version. Always available. '
  DirExists = (PathIsDirectory(StrPtr(Trim$(sDirName))) <> 0)    
End Function

EDIT: You can also use FileSystemObject, but I prefer to avoid the Microsoft Scripting Runtime (including FileSystemObject). In my experience it's occasionally broken on user machines, perhaps because their IT department are paranoid about viruses.

MarkJ
Interesting about the IT sabotage, is that about security or job security? ;)
kenny
+1  A: 
Beaner