Searching a File Tree

Posted on 2006-06-05
Last Modified: 2010-04-23
I have a program running off a CD that creates a File Tree with all the directories on the CD. There are 3 CD's in all.  There are sub-directories that are numbered with 8 digits.  For example, 60003451 or 70003459.  These sub-directories are in all different areas in the File Tree.  Is there a way to create a control that can search for the 8-digit number and take the user to that subdirectory.  All I need is a text box and a button control.  Nothing fancy at all.  Also, if the 8-digit number that the user types in is incorrect, tell the user it's a wrong number or on another CD.  Thanks!
Question by:Heyitsjoe80
    LVL 20

    Expert Comment

    Maybe I'm not knowledgeable enough about VB .NET, but I'm not sure quite what type of data structure you're describing with a "File Tree." I don't see that term used in the online help for either VB 2003 or VB 2005. What type of data structure is holding the information? Do you mean a TreeView?

    If so, I'm not aware of a built-in search command for a TreeView control. You'd have to write your own looping command using a For Each ... Next to go through each node of the control, looking for a match. If you put the entire path in the Tag property for the node, you could then return the tag and move to that directory if the match is made.

    If I'm pointing in the right direction but you're not sure how to handle the details, let me know and I can flesh it out. If I'm all wet, please give us a better sense of how the directory list is structured, and we can take it from there.
    LVL 12

    Accepted Solution

           Dim StartPath As String = "k:\temp\"

            Dim d1 As System.Collections.ObjectModel.ReadOnlyCollection(Of String)
            d1 = My.Computer.FileSystem.GetDirectories(StartPath, FileIO.SearchOption.SearchAllSubDirectories, Me.TextBox1.Text)

            Select Case d1.Count
                Case 0
                    MsgBox("Not found")
                Case 1
                    MsgBox("Found on this path: " & d1(0))
                Case Else
                    MsgBox("Found more than one...")
            End Select

            ' get files in a similar way: My.Computer.FileSystem.GetFiles("k:\temp\", FileIO.SearchOption.SearchAllSubDirectories, Me.TextBox1.Text).Count)
    LVL 12

    Expert Comment

    sorry the commented line should be:

    get files in a similar way: My.Computer.FileSystem.GetFiles(StartPath, FileIO.SearchOption.SearchAllSubDirectories, Me.TextBox1.Text))

    LVL 12

    Expert Comment

    and you can search with wildcards (*.txt) but you dont need that do you. :-)
    LVL 12

    Expert Comment

    My... requires DotNet2 btw (VS 2005)

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now