2009-07-16 60 views
0

如何查找目录是否可用?如何查找网络路径是否可用

使用VB 6.0

databasetext =可用

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

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

如何解决这个问题?

需要VB 6码帮助

回答

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 

2

我用PathIsDirectoryShlwapi.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部门对病毒有偏见。

+0

对IT破坏有意思,是关于安全还是工作安全? ;) – kenny 2009-07-20 11:02:43