'一段搜索doc文件的例子
'你需要找出所有硬盘的盘符,然后用CheckFolder("X:")
Option Explicit
Dim m_lngFileCount As Long '注释:定义计数器
Dim m_objFSO As Scripting.FileSystemObject '注释:定义文件系统对象
Sub CheckFolder(strPath As String)
Dim objFolder As Scripting.Folder '注释:文件夹对象
Dim objFile As Scripting.File '注释:文件对象
Dim objSubdirs As Scripting.Folders '注释:文件夹集合对象
Dim objLoopFolder As Scripting.Folder '注释:文件夹对象
Set objFolder = m_objFSO.GetFolder(strPath)
For Each objFile In objFolder.Files
If UCase$(Right$(objFile.Path, 4)) = ".doc" Or UCase$(Right$(objFile.Path, 4)) = ".DOC" Then
m_lngFileCount = m_lngFileCount + 1
End If
Next objFile
Set objSubdirs = objFolder.SubFolders
For Each objLoopFolder In objSubdirs
CheckFolder objLoopFolder.Path
Next objLoopFolder