用VB怎样搜索包含“QQ”的所有文件

来源:百度知道 编辑:UC知道 时间:2024/06/03 22:55:36
如题,搜索桌面上所有包含“QQ”两个字的文件并删除

本例可搜索子目录
控件:Command1,File1,List1

将以下代码复制到Form1中:

Dim fname$, sppath$, FolderPath$
Dim spShell, spFolder, spFolderItem, sfolder, folderitem, subf, subitem

Private Sub Command1_Click()

Set spShell = CreateObject("Shell.Application")
Set spFolder = spShell.BrowseForFolder(0, "选择目录:", 0, "")
Set spFolderItem = spFolder.Self
sppath = spFolderItem.Path
If Right(sppath, 1) <> "\" Then sppath = sppath & "\"
Call showalldirs

For i = 0 To List1.ListCount - 1
File1.Path = List1.List(i)
For j = 0 To File1.ListCount - 1
If InStr(1, UCase(File1.List(j)), "QQ") Then Kill File1.Path & "\" & File1.List(j)
Next j

Next i

End Sub

Private Sub showalldirs()
List1.Clear
Dim fol, fso, fil, fils, s, f, fldr
Set fso = CreateObject("Script