How to find if the network path is available or not

前端 未结 2 706
失恋的感觉
失恋的感觉 2020-12-22 07:32

How to find if the directory is available or not?

Using VB 6.0

databasetext = network path available

If Len(Dir(databasetext)) = False Then
M         


        
相关标签:
2条回答
  • 2020-12-22 08:08

    From my stock library. I think I included all the declarations needed.

    Private Declare Function FindClose Lib "Kernel32" (ByVal hFindFile As Long) As Long
    Private Declare Function FindFirstFile Lib "Kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
    
    Private Const INVALID_HANDLE_VALUE = -1
    Private Const MAX_PATH = 260
    
    Private Type FILETIME
       dwLowDateTime As Long
       dwHighDateTime As Long
    End Type
    
    Private Type WIN32_FIND_DATA
       dwFileAttributes As Long
       ftCreationTime As FILETIME
       ftLastAccessTime As FILETIME
       ftLastWriteTime As FILETIME
       nFileSizeHigh As Long
       nFileSizeLow As Long
       dwReserved0 As Long
       dwReserved1 As Long
       cFileName As String * MAX_PATH
       cAlternate As String * 14
    End Type
    
    Public Function FolderExists(ByVal FolderSpec As String) As Boolean
       Dim rst As Long
       Dim udtW32FindD As WIN32_FIND_DATA
       Dim lngFHandle As Long
       Dim strFolder As String 'set to FolderSpec parameter so I can change it
    
       strFolder = FolderSpec
       If Right$(strFolder, 1) <> "\" Then
          strFolder = strFolder & "\"
       End If
       strFolder = strFolder & "*"   'add the wildcard allows finding share roots
    
       lngFHandle = FindFirstFile(strFolder, udtW32FindD)
       If lngFHandle  INVALID_HANDLE_VALUE Then
          Call FindClose(lngFHandle)
          FolderExists = True
       End If
    
    End Function
    
    
    0 讨论(0)
  • 2020-12-22 08:12

    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.

    0 讨论(0)
提交回复
热议问题