• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 201
  • Last Modified:

Searching a File Tree

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!
  • 4
1 Solution
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.
       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)
sorry the commented line should be:

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

and you can search with wildcards (*.txt) but you dont need that do you. :-)
My... requires DotNet2 btw (VS 2005)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now