如何查找网络路径是否可用 [英] How to find if the network path is available or not

查看:33
本文介绍了如何查找网络路径是否可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何查找目录是否可用?

使用 VB 6.0

databasetext = 可用的网络路径

If Len(Dir(databasetext)) = False ThenMsgBox "数据库路径不可用"万一

我正在从网络路径中选择文件,如果网络路径不可用,则显示错误文件名或编号错误"

如何解决这个问题?

需要 VB 6 代码帮助

解决方案

来自我的库存库.我想我包含了所有需要的声明.

<前>私有声明函数 FindClose Lib "Kernel32" (ByVal hFindFile As Long) As Long私有声明函数 FindFirstFile Lib "Kernel32" 别名 "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long私有常量 INVALID_HANDLE_VALUE = -1私有常量 MAX_PATH = 260私有类型 FILETIMEdwLowDateTime 一样长dwHighDateTime 一样长结束类型私有类型 WIN32_FIND_DATAdwFileAttributes 长ftCreationTime 作为文件时间ftLastAccessTime 作为 FILETIMEftLastWriteTime 作为 FILETIMEnFileSizeHigh As LongnFileSizeLow As LongdwReserved0 只要dwReserved1 只要cFileName As String * MAX_PATHcAlternate As String * 14结束类型公共函数 FolderExists(ByVal FolderSpec As String) As Boolean暗淡如初Dim udtW32FindD 为 WIN32_FIND_DATADim lngFHandle 尽可能长Dim strFolder As String '设置为 FolderSpec 参数,以便我可以更改它strFolder = FolderSpec如果 Right$(strFolder, 1) <>\"然后strFolder = strFolder & "\"万一strFolder = strFolder & "*" '添加通配符允许查找共享根lngFHandle = FindFirstFile(strFolder, udtW32FindD)如果 lngFHandle INVALID_HANDLE_VALUE 那么调用 FindClose(lngFHandle)文件夹存在 = 真万一结束函数

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

解决方案

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

这篇关于如何查找网络路径是否可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆