vb.net file search

TheDon

Member
Joined
Nov 3, 2003
Messages
5
Im implementing a file search in vb.net using a recursive algorithm, for each of the directories in a directory it itterates calling itself, then checks the files in the directory.

My problem is that its jumping back out of the recursion before it reaches the end of the directory tree, so my current thinking is maybe the call stack is full of the recursive method calls?

The program doesnt give any errors, or break, and carries on as if everything was working fine. If i take out the recursiveness it lists all the directories correctly, so it is deffinatly able to read them all.

Any ideas how to sort this?

This is the code I am using :-

Sub DirSearch(ByVal sDir As String)
Dim d As String
Dim f As String

Try
For Each d In Directory.GetDirectories(sDir)
DirSearch(d)
For Each f In Directory.GetFiles(d, "*")
Check_Files(f)
Next

RaiseEvent CurrentDir(d)

Next

Catch excpt As System.Exception
Debug.WriteLine(excpt.Message)
End Try
End Sub
 
What does the Check_Files function do? Is there any code handling the CurrentDir event?

Just pasted your code into a new project and commented out the raiseevent line and simple made a dummy Check_files function that just did a Debug.WriteLine of the file name and it worked fine on my local drives.
How deep are the recursions going?
 
check_files checks each file against a list of file names stored in a text file.

CurrentDir is just used to pass the current directory to the form to display it as a label.

The search class is being ran as a thread is that makes any difference.

As its recursively calling itself for each directory its hard to keep track of how deep the recursions are going.......

On my c: Its scanning everything up to near the end of my program files directory, when it jumps out, moves to c:\recycler then ends without doing c:\windows, which is after checking a total of 4335 directories.

Then on my d: it scans 15 directories completly, before stopping leaving another 3 completly unscanned, which is after scanning a total of 2545 directories.

Windows reads my c: as having 5,085 folders, and d: as having 2661.
 
Also, just commented out the check files routine, and its listing the directory structure correctly, so maybe the ammount of calls to that is filling the callstack?
 
At the moment the check files routine is completly empty... thought it could be something in there so I commented it all out, and it still does the same.
 
Back
Top