Option Explicit
Const WINDOW_HANDLE = 0
Const OPTIONS = 0
Const FILE_TYPE = "*.tmp"
Dim objShell
Dim objFolder
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder(WINDOW_HANDLE, "选择文加夹:", OPTIONS,"")
If VarType(objFolder) = vbString Then
Dim fso
Set fso = CreateObject("scripting.filesystemobject")
Call DeleteFileInFolder(objFolder.Items.Item.Path, FILE_TYPE)
Set fso = nothing
End if
Set objShell = nothing
'================sub=======================
'迭代删除文件夹及其子文件夹中所有word后缀的文件
Sub DeleteFileInFolder(byval path, byval word)
On Error Resume next
Call fso.DeleteFile(path & "/" & word, True)
If Err <> 0 Then
Err = 0
end if
Dim folder
Set folder = fso.GetFolder(path)
Dim subFolder
For Each subFolder In folder.SubFolders
Call DeleteFileInFolder(subFolder.Path, word)
Next
End sub