Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
Hello everyone,
I have a big dilemma. I am making a folder searcher, and if search term is found, then list all files in that folder. This is what I have:
VB
If CheckBox1.Checked Then
            For Each FOLDER As String In IO.Directory.GetDirectories(frmMain.SnippetsFolder)
                If CheckBox3.Checked Then
                    If FOLDER.Replace(IO.Directory.GetParent(FOLDER).FullName, "").Contains(TextBox1.Text) Then
                        frmMain.TreeView1.Nodes.Add("Folder", My.Computer.FileSystem.GetName(FOLDER))
                        For Each File As String In IO.Directory.GetFiles(FOLDER, "*.cdbf")
                            Dim specFile As String = My.Computer.FileSystem.GetName(File)
                            Dim specIndex As Integer = specFile.LastIndexOf(".")
                            frmMain.TreeView1.Nodes(i).Nodes.Add("Item", specFile.Remove(specIndex), 1, 1)
                        Next
                        'i += 1
                    End If
                Else
                    If FOLDER.Replace(IO.Directory.GetParent(FOLDER).FullName, "").ToLower.Contains(TextBox1.Text.ToLower) Then
                        frmMain.TreeView1.Nodes.Add("Folder", My.Computer.FileSystem.GetName(FOLDER))
                        For Each File As String In IO.Directory.GetFiles(FOLDER, "*.cdbf")
                            Dim specFile As String = My.Computer.FileSystem.GetName(File)
                            Dim specIndex As Integer = specFile.LastIndexOf(".")
                            frmMain.TreeView1.Nodes(i).Nodes.Add("Item", specFile.Remove(specIndex), 1, 1)
                        Next
                        i += 1
                    End If
                End If
            Next
        End If


Unfortunately, I cannot fix this myself. I have stepped in, debugged and whatnot, I just can't find the issue.

The issue is this:
For example, I have an array of treenodes:
Internet
Windows
When I search "Win"
It will give me Windows, insert the files into that treenode. But it inserts another top-level "Windows" treenode, with NO files listed under it.
And if I have multiple top-level folders which fall under the search terms, then it gets even more stuffed up.

If anyone can help, then that would be awesome.

Regards,
iProgramIt

[urgently has been removed]
Posted
Updated 8-Dec-15 10:36am
v4
Comments
phil.o 8-Dec-15 6:51am    
Did you try to debug your code?
iProgramIt 8-Dec-15 16:08pm    
Yes, however I couldn't figure out why it did this issue, as such.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900