Searching Subdirectories within subdirectories
-
Hi, I am using the following code to put all of the mp3 files in the Album directories into an array. This works fine, but what if there were more subdirectories, how can I change this code so that the the computer scans every single directory and subdirectory in f:\mp3 ? Dim strFolder As String = "f:\mp3" For Each strArtist As String In My.Computer.FileSystem.GetDirectories(strFolder) For Each strAlbum As String In My.Computer.FileSystem.GetDirectories(strArtist) For Each strFile As String In My.Computer.FileSystem.GetFiles(strAlbum) If strFile.Substring(strFile.Length - 3) = "mp3" Then objArraylist.Add(strFile) End If Next Next Next Sorry if this is a silly question, but I've only been working with VB.Net for 3 months! Thanks
-
Hi, I am using the following code to put all of the mp3 files in the Album directories into an array. This works fine, but what if there were more subdirectories, how can I change this code so that the the computer scans every single directory and subdirectory in f:\mp3 ? Dim strFolder As String = "f:\mp3" For Each strArtist As String In My.Computer.FileSystem.GetDirectories(strFolder) For Each strAlbum As String In My.Computer.FileSystem.GetDirectories(strArtist) For Each strFile As String In My.Computer.FileSystem.GetFiles(strAlbum) If strFile.Substring(strFile.Length - 3) = "mp3" Then objArraylist.Add(strFile) End If Next Next Next Sorry if this is a silly question, but I've only been working with VB.Net for 3 months! Thanks
I had to do something similiar (find every directory\file path for a server) and came up with the following code. You may be able to modify it for what you need: Dim strpath As String = "f:\mp3" 'Your starting path Dim BaseDir As New DirectoryInfo(strpath) Dim DirListing() As DirectoryInfo DirListing = BaseDir.GetDirectories() Dim tmpFI As FileInfo Dim tmpdir As DirectoryInfo For Each tmpdir In DirListing For Each tmpFI In BaseDir.GetFiles() 'Preforn your check and whatnot Next Next David
-
Hi, I am using the following code to put all of the mp3 files in the Album directories into an array. This works fine, but what if there were more subdirectories, how can I change this code so that the the computer scans every single directory and subdirectory in f:\mp3 ? Dim strFolder As String = "f:\mp3" For Each strArtist As String In My.Computer.FileSystem.GetDirectories(strFolder) For Each strAlbum As String In My.Computer.FileSystem.GetDirectories(strArtist) For Each strFile As String In My.Computer.FileSystem.GetFiles(strAlbum) If strFile.Substring(strFile.Length - 3) = "mp3" Then objArraylist.Add(strFile) End If Next Next Next Sorry if this is a silly question, but I've only been working with VB.Net for 3 months! Thanks
Just set the
FileIO.SearchOption
, like so:My.Computer.FileSystem.GetDirectories(strAlbum, FileIO.SearchOption.SearchAllSubDirectories)
-
Just set the
FileIO.SearchOption
, like so:My.Computer.FileSystem.GetDirectories(strAlbum, FileIO.SearchOption.SearchAllSubDirectories)
Excellent work. Thanks So easy, with such a small piece of code. I did also have to use the next line of code to build a list of the directories, if anyone else needs to use it. Dim dir As ObjectModel.ReadOnlyCollection(Of String) dir = My.Computer.FileSystem.GetDirectories("f:\mp3",FileIO.SearchOption.SearchAllSubDirectories)