微软的文章: http://support.microsoft.com/default.aspx?scid=kb;EN-US;185601 HOW TO: Recursively Search Directories by Using FileSystemObject
'一段搜索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
Set objSubdirs = Nothing Set objFolder = NothingEnd Sub
微软的文章:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;185601
HOW TO: Recursively Search Directories by Using FileSystemObject
'你需要找出所有硬盘的盘符,然后用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
Set objSubdirs = Nothing
Set objFolder = NothingEnd Sub