If Dir("f:\aa.txt") = "" Then MsgBox "no" Else MsgBox "yes" End If
搜索全部 好象有个API 找找相关资料吧
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 Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As LongPrivate Const MAX_PATH = 260Type FILETIME dwLowDateTime As Long dwHighDateTime As Long End Type 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 TypePrivate Const FILE_ATTRIBUTE_DIRECTORY = &H10 Private Const FILE_ATTRIBUTE_NORMAL = &H80Public Function FileExists(FileName As String) As Boolean Dim FindHandle As Long Dim FindData As WIN32_FIND_DATA
On Error GoTo ErrHandler FindHandle = FindFirstFile(FileName, FindData) FileExists = False If FindHandle >= 0 Then If (FindData.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY) = False Then FileExists = True End If End If FindClose (FindHandle) Exit FunctionErrHandler: MsgBox Err.Description End Function
MsgBox "no"
Else
MsgBox "yes"
End If
好象有个API
找找相关资料吧
Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As LongPrivate Const MAX_PATH = 260Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
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 TypePrivate Const FILE_ATTRIBUTE_DIRECTORY = &H10
Private Const FILE_ATTRIBUTE_NORMAL = &H80Public Function FileExists(FileName As String) As Boolean
Dim FindHandle As Long
Dim FindData As WIN32_FIND_DATA
On Error GoTo ErrHandler
FindHandle = FindFirstFile(FileName, FindData)
FileExists = False
If FindHandle >= 0 Then
If (FindData.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY) = False Then
FileExists = True
End If
End If
FindClose (FindHandle)
Exit FunctionErrHandler:
MsgBox Err.Description
End Function