判断一个文件或者文件夹FileOrFolderName在path下是否存在?
(工程中引用Microsoft Scriptiong Runtime)
Public Function IfExistFileOrFolder(path As String, FileOrFolderName As String) As Boolean
Dim fso As New FileSystemObject
Dim folder As folder
Dim subfolder As folder
Dim file As file
Set folder = fso.GetFolder(path)
IfExistFileOrFolder = False
If folder.Files.Count > 0 Then
For Each file In folder.Files
If file.Name = FileOrFolderName Then
IfExistFileOrFolder = True
Exit Function
End If
Next file
End If
If folder.SubFolders.Count > 0 Then
For Each subfolder In folder.SubFolders
If subfolder.Name = FileOrFolderName Then
IfExistFileOrFolder = True
Exit Function
Else
Call IfExistFileOrFolder(subfolder.path, True)
End If
Next subfolder
End If