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. How do I list all the files in a folder and select one.

How do I list all the files in a folder and select one.

Scheduled Pinned Locked Moved Visual Basic
questioncsharp
5 Posts 2 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.
  • D Offline
    D Offline
    directred
    wrote on last edited by
    #1

    In VB.Net is there a simple way of displaying all the files in a selected folder depending on a criteria and how would you display via a message box the file selected. Is it something like as follows. Getting mixed up with VB 6 and .net. I have a dirlistbox, drivelistbox and a filelistbox. I can get a connection between drive and folder but what is the syntax for the files. Feeling stupid here. Private Sub drvLoc_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles drvLoc.SelectedIndexChanged dirLoc.Path = drvLoc.Drive End Sub

    M 1 Reply Last reply
    0
    • D directred

      In VB.Net is there a simple way of displaying all the files in a selected folder depending on a criteria and how would you display via a message box the file selected. Is it something like as follows. Getting mixed up with VB 6 and .net. I have a dirlistbox, drivelistbox and a filelistbox. I can get a connection between drive and folder but what is the syntax for the files. Feeling stupid here. Private Sub drvLoc_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles drvLoc.SelectedIndexChanged dirLoc.Path = drvLoc.Drive End Sub

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

      You would want to use a ComboBox and a ListBox for this. Like so:

      Private Sub DriveComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DriveComboBox.SelectedIndexChanged
      FolderListBox.Items.Clear()
      For Each Dir As String In My.Computer.FileSystem.GetDirectories(DriveComboBox.SelectedItem, FileIO.SearchOption.SearchTopLevelOnly)
      FolderListBox.Items.Add(Dir)
      Next
      End Sub

      Private Sub FolderListBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FolderListBox.SelectedIndexChanged
      FileListBox.Items.Clear()
      For Each File As String In My.Computer.FileSystem.GetFiles(FolderListBox.SelectedItem, FileIO.SearchOption.SearchTopLevelOnly)
      FileListBox.Items.Add(File)
      Next
      End Sub

      Private Sub FileListBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileListBox.SelectedIndexChanged
      MsgBox(FileListBox.SelectedItem)
      End Sub

      The DriveListBox, DirListBox and the FileListBox are not what you would want to use for this. Microsoft doesn't even offer support for these controls anymore. Plus, ListBoxes are a lot more customizable. Hope this helps.


      Trinity: Neo... nobody has ever done this before. Neo: That's why it's going to work.

      D 2 Replies Last reply
      0
      • M MatrixCoder

        You would want to use a ComboBox and a ListBox for this. Like so:

        Private Sub DriveComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DriveComboBox.SelectedIndexChanged
        FolderListBox.Items.Clear()
        For Each Dir As String In My.Computer.FileSystem.GetDirectories(DriveComboBox.SelectedItem, FileIO.SearchOption.SearchTopLevelOnly)
        FolderListBox.Items.Add(Dir)
        Next
        End Sub

        Private Sub FolderListBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FolderListBox.SelectedIndexChanged
        FileListBox.Items.Clear()
        For Each File As String In My.Computer.FileSystem.GetFiles(FolderListBox.SelectedItem, FileIO.SearchOption.SearchTopLevelOnly)
        FileListBox.Items.Add(File)
        Next
        End Sub

        Private Sub FileListBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileListBox.SelectedIndexChanged
        MsgBox(FileListBox.SelectedItem)
        End Sub

        The DriveListBox, DirListBox and the FileListBox are not what you would want to use for this. Microsoft doesn't even offer support for these controls anymore. Plus, ListBoxes are a lot more customizable. Hope this helps.


        Trinity: Neo... nobody has ever done this before. Neo: That's why it's going to work.

        D Offline
        D Offline
        directred
        wrote on last edited by
        #3

        Thanks for this code really appreciate your help.

        1 Reply Last reply
        0
        • M MatrixCoder

          You would want to use a ComboBox and a ListBox for this. Like so:

          Private Sub DriveComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DriveComboBox.SelectedIndexChanged
          FolderListBox.Items.Clear()
          For Each Dir As String In My.Computer.FileSystem.GetDirectories(DriveComboBox.SelectedItem, FileIO.SearchOption.SearchTopLevelOnly)
          FolderListBox.Items.Add(Dir)
          Next
          End Sub

          Private Sub FolderListBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FolderListBox.SelectedIndexChanged
          FileListBox.Items.Clear()
          For Each File As String In My.Computer.FileSystem.GetFiles(FolderListBox.SelectedItem, FileIO.SearchOption.SearchTopLevelOnly)
          FileListBox.Items.Add(File)
          Next
          End Sub

          Private Sub FileListBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileListBox.SelectedIndexChanged
          MsgBox(FileListBox.SelectedItem)
          End Sub

          The DriveListBox, DirListBox and the FileListBox are not what you would want to use for this. Microsoft doesn't even offer support for these controls anymore. Plus, ListBoxes are a lot more customizable. Hope this helps.


          Trinity: Neo... nobody has ever done this before. Neo: That's why it's going to work.

          D Offline
          D Offline
          directred
          wrote on last edited by
          #4

          Forgot to mebtion I am using visual studio 2003 and the name my and FileIO does not work. How is this done in 2003. Sorry for this

          M 1 Reply Last reply
          0
          • D directred

            Forgot to mebtion I am using visual studio 2003 and the name my and FileIO does not work. How is this done in 2003. Sorry for this

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

            Well, I can't really help much with anything in VS2003, but you could go ahead and use a Drive, Directory and File ListBox (since you are using an older version of VS). So, try this:

            Private Sub DriveListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DriveListBox1.SelectedIndexChanged

            DirListBox1.Path = DriveListBox1.Drive

            End Sub

            Private Sub FolderListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DirListBox1.SelectedIndexChanged

            FileListBox1.Path = DirListBox1.Path

            End Sub

            Private Sub FileListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileListBox1.SelectedIndexChanged

            MsgBox(FileListBox1.SelectedItem)

            End Sub

            Hope this helps!


            Trinity: Neo... nobody has ever done this before. Neo: That's why it's going to work.

            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