Results 1 to 2 of 2

Thread: searching harddisk for file type

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 1999
    Posts
    24

    Post

    how would i use api to ( lets say ) find all my mp3s on every directory and sub directory.

    i know i have to use something like FindFileFirst and FindFileNext ... i don't quite understand those and i don't understand how to search subdirectories.

    please help. thanks.

  2. #2
    Lively Member
    Join Date
    Dec 1999
    Location
    Karlsruhe, Germany
    Posts
    122

    Post

    Hi,

    sorry, code's a little longer this time:

    Code:
    Private Sub Command1_Click()
        List1.Clear
        Call listfolders("c:\", "*.txt", List1)
    
    End Sub
    
    Sub listfolders(FolderName, FileMask As String, List As ListBox)
    
        Dim sfolders() As String
        Dim fldcount As Long
        Dim filename As String
        
        On Error Resume Next
        
        If Right$(FolderName, 1) <> "\" Then FolderName = FolderName & "\"
        filename = Dir$(FolderName & FileMask)
        
        Do
            If Len(filename) > 0 Then
                List.AddItem FolderName & filename
                DoEvents
                filename = Dir$
            End If
        Loop Until Len(filename) = 0
        
        filename = Dir(FolderName, vbDirectory)
        fldcount = 0
        ReDim sfolders(0)
    
        Do
            If filename <> "." And filename <> ".." Then
                If (GetAttr(FolderName & filename) And vbDirectory) = vbDirectory Then
                    If Err.Number = 0 Then
                        fldcount = fldcount + 1
                        If fldcount = 1 Then
                            ReDim sfolders(1 To fldcount)
                        Else
                            ReDim Preserve sfolders(1 To fldcount)
                        End If
                    
                        sfolders(fldcount) = FolderName & filename
                    Else
                        Err.Clear
                    End If
                End If
            End If
            filename = Dir
        Loop Until Len(filename) = 0
        
        If fldcount > 0 Then
            For fldcount = LBound(sfolders) To UBound(sfolders)
                listfolders sfolders(fldcount), FileMask, List
            Next
        End If
                    
    End Sub
    Roger

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