Results 1 to 5 of 5

Thread: how do i make all of like .mp3, show up on one filelist box?

  1. #1

    Thread Starter
    Hyperactive Member flame_211's Avatar
    Join Date
    Jun 2000
    Location
    I dont really think I know where I am???
    Posts
    393

    Question

    how do i make all of like .mp3, show up on one filelist box?
    Reach me at:
    AIM: FlameWide
    AIM: Itz deep6
    MSN/Email: [email protected]

    Check out these sites:
    My Blog

  2. #2
    Guest
    Change the Pattern to *.MP3

  3. #3

    Thread Starter
    Hyperactive Member flame_211's Avatar
    Join Date
    Jun 2000
    Location
    I dont really think I know where I am???
    Posts
    393

    Unhappy thanx

    no i mean like, out of the whole computer not just 1 file
    Reach me at:
    AIM: FlameWide
    AIM: Itz deep6
    MSN/Email: [email protected]

    Check out these sites:
    My Blog

  4. #4
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357
    Try referencing the Microsoft Scripting Runtime library, and use the FileSystemObject to search through all the drives and folders in the computer (you can even go over a network).

    Grab any file whose Right$(File.Name, 3) = "mp3" and display the File.Path in the listbox.
    ~seaweed

  5. #5
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357

    Talking Try this on for size

    Well, you got me curious, so I decided to try my own suggestion to see if it works. To use this code, drop a Label, a Command Button, and a List Box on a form. Make the form nice and big and strech the list box to cover it (we're displaying the path info here). Also, stretch the label across the top of the form and make it about three text lines tall. Put the command button anywhere.

    Leave the default names for the controls for this code to work, and don't forget to go to Project/References... and select "Microsoft Scripting Runtime".

    This program searches all hard drives for .bmp, .jpg, .mp3, and .img files (you can, of course, search for whatever you want). It then displays the path of each one found in the list box.

    Here goes. In the code window for your form, paste this:
    Code:
    Option Explicit
    
    Private gbStopSearching As Boolean
    
    Private Sub Form_Load()
        ' This just sets up the command button and global stop flag...
        gbStopSearching = False
        Command1.Value = True
    End Sub
    
    Private Sub Command1_Click()
        ' Check value of global flag for caption and action (start or stop searching)
        If gbStopSearching Then
            Command1.Caption = "Stop searching"
            gbStopSearching = False
            ' They want to search, so clear list and start searching
            List1.Clear
            Call FillListFromAllDrivesAndTheirFolders(List1)
        Else
            Command1.Caption = "Start searching"
            gbStopSearching = True   ' This is checked by search function and will stop the search
        End If
    End Sub
    
    Private Sub FillListFromAllDrivesAndTheirFolders(aoListBox As ListBox)
        Dim loFileSysObj As FileSystemObject
        Dim loFolder As Folder
        Dim loDrive As Drive
        
        Set loFileSysObj = New FileSystemObject
        
        For Each loDrive In loFileSysObj.Drives
            ' This routine searches only local hard drives (DriveType = Fixed)
            If loDrive.DriveType = Fixed Then
                Set loFolder = loFileSysObj.GetFolder(loDrive.DriveLetter & ":\")
                ' Call the recursive function to search all subFolders this each drive
                Call GetFilesFromFolderAndSubFolders(loFolder, aoListBox)
            End If
        Next ' loDrive
        
        ' I always do this, not sure if it's necessary...
        Set loFolder = Nothing
        Set loFileSysObj = Nothing
    End Sub
    
    Private Sub GetFilesFromFolderAndSubFolders(aoFolder As Folder, _
                                                aoListBox As ListBox)
        Dim loFile As File
        Dim loFolder As Folder
        
        ' This is a recursive function that calls itself until it reaches
        ' the last sub folder in each folder (It searches EVERYWHERE).
        For Each loFolder In aoFolder.SubFolders
            ' First check if they want to stop searching, and exit if they do
            If gbStopSearching Then
                Exit For
            End If
            
            GetFilesFromFolderAndSubFolders loFolder, aoListBox
            DoEvents    ' Allows for screen updating and pushing of command button
        Next ' loFolder
        
        ' Once all folders have been searched, add the files from this
        ' folder to the list
        For Each loFile In aoFolder.Files
            ' First check if they want to stop searching, and exit if they do
            If gbStopSearching Then
                Exit For
            Else
                ' This label lets the user know something is happening if the list isn't
                ' being filled.  Make the label about 3 lines high and several inches wide
                Label1 = "Searching..." & vbNewLine & loFile.Path
                
                ' Here we only display the file types we want to find...
                If Right$(loFile.Name, 3) = "img" Or _
                    Right$(loFile.Name, 3) = "jpg" Or _
                    Right$(loFile.Name, 3) = "mp3" Or _
                    Right$(loFile.Name, 3) = "bmp" Then
                        aoListBox.AddItem loFile.Path
                End If
            End If
            DoEvents   ' Allows for screen updating and pushing of command button
        Next ' loFile
    End Sub
    ~seaweed

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