如何判断网络路径是否有效
如有一网络路径:\\192.168.1.5\temp\xx.jpg 请问有什么办法可以快速判断该路径是否有效呢?关键是要快速,如遇上网络不通时,要可以快速响应用户。
[解决办法]
用程序在后台模拟download试试
[解决办法]
这样可试一试:
Private Sub Command1_Click()
Dim cNetFile As String
cNetFile = "\\192.168.1.5\temp\xx.jpg "
If FileCheck(cNetFile) = True Then
MsgBox "ok "
Else
MsgBox "err "
End If
End Sub
Private Function FileCheck(Filename As String) As Boolean
Dim FileId As Long
On Error Resume Next
FileId = FreeFile()
Open Filename For Input As #FileId
Close #FileId
FileCheck = (Err.Number = 0)
Err.Clear
End Function
[解决办法]
'不管是Local Folder还是UNC Path:
Public Property Get PathIsValid(ByVal sPath As String) As Boolean
Dim uWFD As WIN32_FIND_DATA
Dim hSearch As Long
sPath = sPath & IIf(Right$(sPath, 1) <> "\ ", "\ ", vbNullString)
If bIsNT Then
hSearch = FindFirstFileW(StrPtr(sPath & "*.* " & vbNullChar), uWFD)
Else
hSearch = FindFirstFile(sPath & "*.* " & vbNullChar, uWFD)
End If
PathIsValid = (hSearch <> INVALID_HANDLE_VALUE)
Call FindClose(hSearch)
End If
End Property