by Cyric (1 Submission)
Category: Files/File Controls/Input/Output
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Wed 13th June 2001
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Searches through the specified folder (through the use of a dialog box) for all .MP3 files and adds them to a list box. If the ID3 information
API Declarations
Public Type SHITEMID 'mkid
cb As Long
abID As Byte
End Type
Public Type ITEMIDLIST 'idl
mkid As SHITEMID
End Type
Public Type BROWSEINFO 'bi
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type
Public Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Public Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
Public Const BIF_RETURNONLYFSDIRS = &H1
'GLOBAL VARIABLES USED FOR MAIN APPLICATION
Public FSO As FileSystemObject
Public BI As BROWSEINFO, IDL As ITEMIDLIST, pidl As Long, pos As Integer, spath As String
'Holds the tag info for an MP3 file
Public Type TagInfo
Tag As String * 3
Songname As String * 30
artist As String * 30
album As String * 30
year As String * 4
comment As String * 30
genre As String * 1
End Type
Private Sub command1_Click()
'Create a file system object so we can gain access to the drives
Set FSO = CreateObject("Scripting.FileSystemObject")
'Set up a browse for folder dialog box
With BI
.hOwner = Me.hWnd
.pidlRoot = 0&
.lpszTitle = "Select the folder to scan"
.ulFlags = BIF_RETURNONLYFSDIRS
End With
'Capture the path from the folder dialog box
pidl& = SHBrowseForFolder(BI): spath$ = Space$(512): Call SHGetPathFromIDList(ByVal pidl&, ByVal spath$)
Dim PATH As String: PATH = (Left(spath$, InStr(spath$, Chr$(0)) - 1))
'Assuming the user actually selected a folder
If PATH <> "" Then
'Make sure the path has a \ at the end
If Right(PATH, 1) <> "\" Then PATH = PATH & "\"
FolderList (PATH)
'Dont forget to add the root folder files as well :)
FileList (PATH)
End If
Set FSO = Nothing
End Sub
'Scans through FOLDER looking for files and subfolders
Private Sub FolderList(folder As String)
Dim SUBFOL, FOL
Set SUBFOL = FSO.GetFolder(folder).SubFolders
For Each FOL In SUBFOL
FileList (FOL.PATH & "\")
FolderList (FOL.PATH & "\")
Next
Set SUBFOL = Nothing
End Sub
'Adds the specified file types to the list box
Private Sub FileList(subfolder As String)
Dim SUBFILE, FILE
Set FILE = FSO.GetFolder(subfolder).FILES
For Each SUBFILE In FILE
'Make sure this is an MP3
If UCase(Right(SUBFILE.PATH, 3)) = "MP3" Then AddFile (SUBFILE.PATH)
Next
Set FILE = Nothing
End Sub
'Adds a file to the play list, if ID3 info exists that is added as well
Private Sub AddFile(filepath As String)
On Error Resume Next
Open filepath For Binary As #1
Dim CurrentTag As TagInfo
With CurrentTag
'Find out if there is any tag info attached
Get #1, FileLen(filepath) - 127, .Tag
'Bail out if there is no tag
If Not .Tag = "TAG" Then List1.AddItem Mid$(filepath, InStrRev(filepath, "\") + 1, Len(Mid$(filepath, InStrRev(filepath, "\") + 1)) - 4): Close #1: Exit Sub
'Grab the tag details
Get #1, , .Songname
Get #1, , .artist
Get #1, , .album
Get #1, , .year
Get #1, , .comment
Get #1, , .genre
Close #1
'Add the mp3 to the playlist
List1.AddItem (RTrim(.Songname) & " - " & RTrim(.artist))
'Asc(RTrim(.genre))
End With
End Sub
No comments have been posted about Searches through the specified folder (through the use of a dialog box) for all .MP3 files and adds. Why not be the first to post a comment about Searches through the specified folder (through the use of a dialog box) for all .MP3 files and adds.