Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Searching Subdirectories within subdirectories

Searching Subdirectories within subdirectories

Scheduled Pinned Locked Moved Visual Basic
questioncsharpalgorithmsdata-structures
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    portreathbeach
    wrote on last edited by
    #1

    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

    D M 2 Replies Last reply
    0
    • P portreathbeach

      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

      D Offline
      D Offline
      dhbaer
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • P portreathbeach

        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

        M Offline
        M Offline
        MatrixCoder
        wrote on last edited by
        #3

        Just set the FileIO.SearchOption, like so:

        My.Computer.FileSystem.GetDirectories(strAlbum, FileIO.SearchOption.SearchAllSubDirectories)

        P 1 Reply Last reply
        0
        • M MatrixCoder

          Just set the FileIO.SearchOption, like so:

          My.Computer.FileSystem.GetDirectories(strAlbum, FileIO.SearchOption.SearchAllSubDirectories)

          P Offline
          P Offline
          portreathbeach
          wrote on last edited by
          #4

          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)

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups