'目录是否存在?Public Function DirExists(ByVal strDirName As String) As Boolean
On Error Resume Next DirExists = (GetAttr(strDirName) And vbDirectory) = vbDirectory Err.Clear
End Function
On Error Resume Next DirExists = (GetAttr(strDirName) And vbDirectory) = vbDirectory Err.Clear
End Function
' Checks 'filename$' to find wether the filename given
' exists.
'
' Parameters
' Name Type Value
' -------------------------------------------------------------
' filename$ String The filename to be checked
'
' Returns
' True if the file exists
' False if the file does not exist
'
' Last updated by Jens Balchen 21.11.95
Dim f% ' Trap any errors that may occur
On Error Resume Next ' Get a free file handle to avoid using a file handle already in use
f% = FreeFile
' Open the file for reading
Open filename$ For Input As #f%
' Close it
Close #f%
' If there was an error, Err will be <> 0. In that case, we return False
FileExists% = Not (Err <> 0)End Function
假设你要找 "c:\windows" 下的 "system" 目录!
if Dir("c:\windows\system",vbDirectory)="" then
'--没有该目录
...
else
'--- 该目录存在!
end if
........
else '不存在 .....end if