|
-
Jun 19th, 2000, 06:52 AM
#1
Thread Starter
Hyperactive Member
how do i make all of like .mp3, show up on one filelist box?
-
Jun 19th, 2000, 06:55 AM
#2
Change the Pattern to *.MP3
-
Jun 19th, 2000, 06:58 AM
#3
Thread Starter
Hyperactive Member
thanx
no i mean like, out of the whole computer not just 1 file
-
Jun 19th, 2000, 07:08 AM
#4
Frenzied Member
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.
-
Jun 19th, 2000, 08:21 AM
#5
Frenzied Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|