Results 1 to 4 of 4

Thread: searching all folders...

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2001
    Location
    Sweden
    Posts
    2

    Question

    I want help with some code to search all folders in a directory....

  2. #2
    Fanatic Member Jerry Grant's Avatar
    Join Date
    Jul 2000
    Location
    Dorset, UK
    Posts
    810
    Search folders for what? Specific file, files or text in file(s)?
    Jerry Grant................tnarG yrreJ
    Website: <JG-Design></.net>
    Email: [email protected]
    Working towards a bug free world......
    (Not a Microsoft employee)

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2001
    Location
    Sweden
    Posts
    2
    I want to search for tif-files on the cd in all folders...

  4. #4
    Guest
    Searches for *.mp3 in C: but this can be changed easily...

    Code:
    'objects
    '1 cmd button
    '1 list box
    
    '*********************
    Private Sub Command1_Click()
        List1.Clear
        Me.MousePointer = vbHourglass
        GetAllDirsFrom "c:"
        Me.MousePointer = vbNormal
    End Sub
    
    Private Function GetAllDirsFrom(ByVal pstrDir As String)
        Dim fso As FileSystemObject
        Dim fldrMain As Folder
        Dim fldrsSub As Folders
        Dim fldr As Folder
        
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set fldrMain = fso.GetFolder(pstrDir & "\")
        If Right(fldrMain.Path, 1) = "\" Then
            AddAllFilesFrom Left(fldrMain.Path, Len(fldrMain.Path) - 1)
        Else
            AddAllFilesFrom fldrMain.Path
        End If
        ' Recurse subdirectories
        Set fldrsSub = fldrMain.SubFolders
        For Each fldr In fldrsSub
            GetAllDirsFrom fldr.Path
        Next
        DoEvents
    End Function
    
    Private Function AddAllFilesFrom(ByVal pstrDir As String)
        strFile = pstrDir & "\" & Dir(pstrDir & "\*.mp3")
        Do Until strFile = pstrDir & "\"
            List1.AddItem strFile
            strFile = pstrDir & "\" & Dir
        Loop
    End Function
    hope this helps
    ~~~~~~~~~~
    ~~Chenko~~
    ~~~~~~~~~~

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