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. multiple file search

multiple file search

Scheduled Pinned Locked Moved Visual Basic
question
8 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.
  • J Offline
    J Offline
    jds1207
    wrote on last edited by
    #1

    have my program working but need to be able to search for files of multiple file types and search for multiple drives at the same time. Right now I can only search for one files type by typing the extension into a textbox. To search for the drive, i created a BrowseFolderDialog to search folder on a specific drive and the path is displayed in a textbox. So I have two question: Is there a way for me to search for multiple file types by typing the extensions in the textbox at the same time? Is there a way to search for more than one drive in a text box at one time? Here is some code: Private Sub GetDirectoryContents() Dim FilePattern As String = "*." & TextBox2.Text.Trim Dim sdir As String = TextBox1.Text.Trim Dim dDir As New DirectoryInfo(sdir) Dim fi As FileSystemInfo For Each fi In dDir.GetFileSystemInfos(FilePattern) ListBox1.Items.Add(fi.Name) Next End Sub This is the class I created to search for the folders: Dim MyBrowseFolder As New FolderBrowser() Public Function ShowDialog(ByVal browseFolderTitle As String) With MyBrowseFolder .Style = FolderBrowserStyles.BrowseForComputer .StartLocation = FolderBrowserFolder.MyComputer & .StartLocation = FolderBrowserFolder.MyDocuments 'Dialog box title .Description = browseFolderTitle .ShowDialog() 'Return the folder path. ShowDialog = .DirectoryPath jds1207

    P 1 Reply Last reply
    0
    • J jds1207

      have my program working but need to be able to search for files of multiple file types and search for multiple drives at the same time. Right now I can only search for one files type by typing the extension into a textbox. To search for the drive, i created a BrowseFolderDialog to search folder on a specific drive and the path is displayed in a textbox. So I have two question: Is there a way for me to search for multiple file types by typing the extensions in the textbox at the same time? Is there a way to search for more than one drive in a text box at one time? Here is some code: Private Sub GetDirectoryContents() Dim FilePattern As String = "*." & TextBox2.Text.Trim Dim sdir As String = TextBox1.Text.Trim Dim dDir As New DirectoryInfo(sdir) Dim fi As FileSystemInfo For Each fi In dDir.GetFileSystemInfos(FilePattern) ListBox1.Items.Add(fi.Name) Next End Sub This is the class I created to search for the folders: Dim MyBrowseFolder As New FolderBrowser() Public Function ShowDialog(ByVal browseFolderTitle As String) With MyBrowseFolder .Style = FolderBrowserStyles.BrowseForComputer .StartLocation = FolderBrowserFolder.MyComputer & .StartLocation = FolderBrowserFolder.MyDocuments 'Dialog box title .Description = browseFolderTitle .ShowDialog() 'Return the folder path. ShowDialog = .DirectoryPath jds1207

      P Offline
      P Offline
      P P Vilsad
      wrote on last edited by
      #2

      let the users type multiple extensions to a textbox seperated by commas. create a thread to search a specific extension in your path and then run multiple instances of that thread with one extension in each thread. since you have the code convert the function you are using to a thread

      Vilsad P P MCTS (Windows Applications) .Net 2.0

      J 1 Reply Last reply
      0
      • P P P Vilsad

        let the users type multiple extensions to a textbox seperated by commas. create a thread to search a specific extension in your path and then run multiple instances of that thread with one extension in each thread. since you have the code convert the function you are using to a thread

        Vilsad P P MCTS (Windows Applications) .Net 2.0

        J Offline
        J Offline
        jds1207
        wrote on last edited by
        #3

        How do I create a thread?

        P 1 Reply Last reply
        0
        • J jds1207

          How do I create a thread?

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

          http://www.codeproject.com/vb/net/threadingvbnet.asp[^]

          Vilsad P P MCTS (Windows Applications) .Net 2.0

          J 1 Reply Last reply
          0
          • P P P Vilsad

            http://www.codeproject.com/vb/net/threadingvbnet.asp[^]

            Vilsad P P MCTS (Windows Applications) .Net 2.0

            J Offline
            J Offline
            jds1207
            wrote on last edited by
            #5

            Is this correct because its still not working? Dim MyThread As New System.Threading.Thread(AddressOf GetDirectoryContents) MyThread.Start() It may seem simple but I've never worked with threads before.

            P 1 Reply Last reply
            0
            • J jds1207

              Is this correct because its still not working? Dim MyThread As New System.Threading.Thread(AddressOf GetDirectoryContents) MyThread.Start() It may seem simple but I've never worked with threads before.

              P Offline
              P Offline
              P P Vilsad
              wrote on last edited by
              #6

              Threading is a advanced topic to understand in a few minuts. i thing you should search in MSDN and a overall knowledge about threads and threads in vb.net first. then write your program, thread functions are not like ordinary functions, and when handling you should be more cautious because you may end up in thread locks. but threads are good practice if you want your program run in a faster way (by deviding the work load to multiple threads so you can get all the work done simultaniously)

              jds1207 wrote:

              Dim MyThread As New System.Threading.Thread(AddressOf GetDirectoryContents) MyThread.Start()

              there is no problem with your code, what is the error you are getting ?

              Vilsad P P MCTS (Windows Applications) .Net 2.0

              J 1 Reply Last reply
              0
              • P P P Vilsad

                Threading is a advanced topic to understand in a few minuts. i thing you should search in MSDN and a overall knowledge about threads and threads in vb.net first. then write your program, thread functions are not like ordinary functions, and when handling you should be more cautious because you may end up in thread locks. but threads are good practice if you want your program run in a faster way (by deviding the work load to multiple threads so you can get all the work done simultaniously)

                jds1207 wrote:

                Dim MyThread As New System.Threading.Thread(AddressOf GetDirectoryContents) MyThread.Start()

                there is no problem with your code, what is the error you are getting ?

                Vilsad P P MCTS (Windows Applications) .Net 2.0

                J Offline
                J Offline
                jds1207
                wrote on last edited by
                #7

                Error: Cross-thread operation not valid: Control 'ListBox1' accessed from a thread other than the thread it was created on. Right now, when I do the file search I type the file type in the textbox(txt) and the files with those types are displayed in a listbox. I want to change it so I can type in for example, txt, bmp, log into the textbox and display all of those file types in the listbox together. Is threading the only solution for this?

                P 1 Reply Last reply
                0
                • J jds1207

                  Error: Cross-thread operation not valid: Control 'ListBox1' accessed from a thread other than the thread it was created on. Right now, when I do the file search I type the file type in the textbox(txt) and the files with those types are displayed in a listbox. I want to change it so I can type in for example, txt, bmp, log into the textbox and display all of those file types in the listbox together. Is threading the only solution for this?

                  P Offline
                  P Offline
                  P P Vilsad
                  wrote on last edited by
                  #8

                  you can't directly use the objects you created in your application inside the thread, you can do your multiple extension search without a thread too, but you will have to search one by one extensions,but this will consume some time

                  Vilsad P P MCTS (Windows Applications) .Net 2.0

                  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