如何找到如果网络路径是否可用(How to find if the network path is

2019-06-26 02:33发布

如何找到如果该目录是否可用?

用VB 6.0

databasetext =可用的网络路径

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

我选择从网络路径的文件,如果网络路径不可用,则显示错误“错误的文件名称或号码”

如何解决这个问题呢?

需要VB 6代码帮助

Answer 1:

从我的股票库。 我想我包括所需的所有声明。

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



Answer 2:

我用PathIsDirectory从Shlwapi.dll中 。 下面是一些VB6代码:

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

编辑:您还可以使用FileSystemObject的,但我更喜欢以避免Microsoft脚本运行(包括FileSystemObject的)。 在我的经验,它偶尔打破用户的机器,也许是因为他们的IT部门是偏执病毒。



文章来源: How to find if the network path is available or not
标签: vb6