|
本帖最后由 阳光下的橙子 于 2011-8-1 14:50 编辑
我也写了一段脚本,能实现对文件夹下各种后缀文件的遍历,包括根目录和子目录
folderspec = 文件夹路径
Function ShowFilename(folderspec)
Dim fso,f,f1,sf,k,str,fs,sfd,filetype
filetype = LCase(InputBox ("请输入你想要搜索的文件后缀名,比如txt","搜索自定义"))
k = 0
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set fs = f.SubFolders
If fs.Count > 0 Then
Num = fs.Count
MsgBox "存在"&Num&"个子文件夹", ,"文件夹搜索提示"
For Each sfd In fs
For Each f1 In sfd.Files
str = ""
i = Len(f1)
For j = i-2 To i
str = str & Mid(f1,j,1)
Next
If str = filetype Then
k = k+1
End If
Next
Next
Set sf = f.Files
For Each f1 in sf
str = ""
i = Len(f1)
For j = i-2 To i
str = str & Mid(f1,j,1)
Next
If str = filetype Then
k = k+1
End if
Next
Else
MsgBox "不存在子文件夹,直接遍历根目录", ,"文件夹搜索提示"
Set sf = f.Files
For Each f1 in sf
str = ""
i = Len(f1)
For j = i-2 To i
str = str & Mid(f1,j,1)
Next
If str = filetype Then
k = k+1
End if
Next
End If
MsgBox "一共有"&k&"个"&filetype&"文件!"
End Function |
|