[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 199
  • 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!
0
Heyitsjoe80
Asked:
Heyitsjoe80
  • 4
1 Solution
 
ElrondCTCommented:
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.
0
 
vb_jonasCommented:
       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)
0
 
vb_jonasCommented:
sorry the commented line should be:

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

0
 
vb_jonasCommented:
and you can search with wildcards (*.txt) but you dont need that do you. :-)
0
 
vb_jonasCommented:
My... requires DotNet2 btw (VS 2005)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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