我用dir(PATH,vbDirectory)的返回值来判断给定的PATH是否存在。
存在的话,则执行shell "cmd /c rd /s/q " & path 来删除该目录以上两步工作周期性的调用
可是会出现一个目录明明存在,却被认定为不存在了请诸位大侠帮忙想想会是什么可能呢?拜托拜托
存在的话,则执行shell "cmd /c rd /s/q " & path 来删除该目录以上两步工作周期性的调用
可是会出现一个目录明明存在,却被认定为不存在了请诸位大侠帮忙想想会是什么可能呢?拜托拜托
Public Function DirExists(ByVal strDirName As String) As Boolean
On Error Resume Next DirExists = (GetAttr(strDirName) And vbDirectory) = vbDirectory Err.Clear
End Function
Public Function FileExists(ByVal strFileName As String) As Boolean
On Error Resume Next
FileExists = (GetAttr(strFileName) And vbArchive) = vbArchive Err.Clear
End Function
Dim fsoTest As New FileSystemObjectIf fsoTest.FolderExists(App.Path & "\ABC") = True Then
MsgBox "此文件存在"
Else
MsgBox "天呀,没有呀!"
End If
End Sub
Dim tempValue
On Error GoTo acd
tempValue = GetAttr(FileName)
folderExists = True
Exit Function
acd:
folderExists = False
End FunctionPrivate Sub Command1_Click()
if folderExists("f:\rcc")=true then
MsgBox "此文件夹存在"
else
msgbox "不存在"
end if
End Sub
Option ExplicitPrivate 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 * 260
cAlternate As String * 14
End Type
Private Const FILE_ATTRIBUTE_DIRECTORY = &H10
Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
Private Function FindDir(strPath As String) As Boolean
Dim tFindData As WIN32_FIND_DATA, lngFileHandle As Long, bRet As Boolean
bRet = False
lngFileHandle = FindFirstFile(strPath, tFindData)
If lngFileHandle <> -1 Then
If (tFindData.dwFileAttributes And FILE_ATTRIBUTE_DIRECTORY) Then
bRet = True
End If
End If
FindDir = bRet
End FunctionPrivate Sub Command1_Click()
MsgBox FindDir("C:\Winnt")
End Sub
他先使用GetAttr 来读取 文件的属性 如果不存在 就触发一个错误
偶没试过GetAttr 这个函数是不是稳定,不过效率来讲,小弟的方法应该快点
2.目录是系统或隐藏属性的.
把程序给客户了,不知道在那头儿运行结果如何,周一见了
:)