我要通过在一个文本框中输入一个目录的名字,然后根据此名字在硬盘上进行模糊查寻,然后把结果输出来,我是通过Dirlistbox控件做的。
能给我一段小代码吗?谢谢!

解决方案 »

  1.   


    微软的文章:
    http://support.microsoft.com/default.aspx?scid=kb;EN-US;185601
    HOW TO: Recursively Search Directories by Using FileSystemObject
      

  2.   

    '一段搜索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