|
Dim fso As Object '模块级变量
Dim SourcePath As String
'主程序:通过递归,执行指定的操作
Sub main()
Set fso = CreateObject("scripting.filesystemobject")
SourcePath = getFolderPath("请选择源路径")
If SourcePath = "" Then End
Call Recursion(SourcePath)
End Sub
'获取文件夹路径
Function getFolderPath(prompt) As String
Dim Objshell As Object, Objfolder As Object
Set Objshell = CreateObject("Shell.Application")
Set Objfolder = Objshell.BrowseForFolder(0, prompt, 0, 0)
If Objfolder Is Nothing Then getFolderPath = "" Else getFolderPath = Objfolder.self.Path
Set Objfolder = Nothing: Set Objshell = Nothing
End Function
'递归程序
Sub Recursion(myPath As String)
Dim myFolder As Object, mySubFolder As Object, myFile As Object, x
Set myFolder = fso.getfolder(myPath)
'遍历文件夹
For Each mySubFolder In myFolder.SubFolders
Recursion mySubFolder.Path
Next
'遍历文件
For Each myFile In myFolder.Files
x = Left(fso.GetBaseName(myFile), 1)
If x = "A" Or x = "a" Then fso.DeleteFile myFile
Next
End Sub
1.rar
(8.91 KB, 下载次数: 7)
|
|