使用这些功函数来确定是否是一个文件或目录。
使用示例:FileExists("C:\Data\MyFile.mdb")
FolderExists("C:\Windows\System")
函数代码如下:
Function FileExists(ByVal strFile As String, Optional bFindFolders As Boolean) As Boolean
Dim lngAttributes As Long
lngAttributes = (vbReadOnly or vbHidden or vbSystem)
If bFindFolders Then
lngAttributes = (lngAttributes or vbDirectory)
Else
Do While Right$(strFile, 1) = "\"
strFile = Left$(strFile, Len(strFile) - 1)
Loop
End If
On Error Resume Next
FileExists = (Len(Dir(strFile, lngAttributes)) > 0) End Function
Function FolderExists(strPath As String) As Boolean
On Error Resume Next
FolderExists = ((GetAttr(strPath) And vbDirectory) = vbDirectory)
End Function
Function TrailingSlash(varIn As Variant) As String
If Len(varIn) > 0 Then
If Right(varIn, 1) = "\" Then
TrailingSlash = varIn
Else
TrailingSlash = varIn & "\"
End If
End If
End Function