Hey guys.
What I have to do is to search the whole system for any Mp3 files.
My Problem is to loop through all the subfolders.
What I managed to do:
I know there is some easy way to loop through all the sub folders but im not seeing it.Code:Imports System.IO Imports System.Runtime.InteropServices Public Class Form1 Private Structure SHFILEINFO Public hIcon As IntPtr ' : icon Public iIcon As Integer ' : icondex Public dwAttributes As Integer ' : SFGAO_ flags <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)> _ Public szDisplayName As String <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=80)> _ Public szTypeName As String End Structure Private Declare Auto Function SHGetFileInfo Lib "shell32.dll" _ (ByVal pszPath As String, _ ByVal dwFileAttributes As Integer, _ ByRef psfi As SHFILEINFO, _ ByVal cbFileInfo As Integer, _ ByVal uFlags As Integer) As IntPtr Private Const SHGFI_ICON = &H100 Private Const SHGFI_SMALLICON = &H1 Private Const SHGFI_LARGEICON = &H0 ' Large icon Private Const MAX_PATH = 260 Private Sub AddImages(ByVal strFileName As String) Dim shInfo As SHFILEINFO shInfo = New SHFILEINFO() shInfo.szDisplayName = New String(vbNullChar, MAX_PATH) shInfo.szTypeName = New String(vbNullChar, 80) Dim hIcon As IntPtr hIcon = SHGetFileInfo(strFileName, 0, shInfo, Marshal.SizeOf(shInfo), SHGFI_ICON Or SHGFI_SMALLICON) Dim MyIcon As Drawing.Bitmap MyIcon = Drawing.Icon.FromHandle(shInfo.hIcon).ToBitmap ImageList1.Images.Add(strFileName.ToString(), MyIcon) ImageList1.TransparentColor = Color.Black End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim Folders As New List(Of String) Dim SubFolders As New List(Of String) Folders.AddRange(Directory.GetDirectories("C:\")) GetFiles("C:\") For a = 0 To Folders.Count - 1 GetFiles(Folders(a)) Try Dim Gi As IO.DirectoryInfo Dim Di As New DirectoryInfo(Folders(a)) For Each Gi In Di.GetDirectories SubFolders.Add(Gi.FullName) GetFiles(Gi.FullName) Next Catch ex As Exception End Try Next End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ListView1.View = View.Details ListView1.Columns.Add("File Name", 190, HorizontalAlignment.Left) ListView1.Columns.Add("File Type", 50, HorizontalAlignment.Left) ListView1.Columns.Add("Last Accessed", 150, HorizontalAlignment.Left) End Sub Private Sub GetFiles(ByVal Fpath As String) Dim Di As New DirectoryInfo(Fpath) Dim Index As Integer = 0 Dim Fi As IO.FileInfo Try For Each Fi In Di.GetFiles If Path.GetExtension(Fi.FullName).ToUpper = ".MP3" Or Path.GetExtension(Fi.FullName).ToUpper = ".wav" Then AddImages(Fi.FullName) ListView1.Items.Add(Fi.FullName, Index) ListView1.Items(Index).SubItems.Add(Fi.Extension) ListView1.Items(Index).SubItems.Add(Fi.LastAccessTime) Index += 1 End If Next Catch ex As Exception End Try End Sub End Class
Thanks




Reply With Quote