Results 1 to 3 of 3

Thread: Searching for files within subdirectories

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    Ireland
    Posts
    224

    Question

    Hopefully someone can tell me how do I do a search for all files with a .txt extension within a directory and it's subdirectories.
    Thanks a lot for your help
    JK

  2. #2
    Lively Member
    Join Date
    Oct 2000
    Location
    Scotland
    Posts
    96
    Use a filelistbox - you can set the its path and pattern

    fillb.path = "root directory"
    fillb.pattern= "*.txt"

    I'm not too sure if it will look in the subdirectories as well...


    H.
    Just trying to muddle through...

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    Option Explicit
    
    Private Function GetFiles(sPath As String)
    
        Dim fso As Object
         Set fso = CreateObject("Scripting.FileSystemObject")
        Dim sFilename As String
        Dim fld
        
        
        If fso.FolderExists(sPath) Then
            sPath = sPath & IIf(Right$(sPath, 1) <> "\", "\", "")
            sFilename = Dir(sPath & "*.txt")
            Do While Len(sFilename)
                MsgBox sPath & sFilename
                sFilename = Dir
            Loop
            For Each fld In fso.GetFolder(sPath).SubFolders
                GetFiles fld.Path
            Next
        End If
    End Function
    
    Private Sub Command1_Click()
        Call GetFiles("C:\my documents")
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width