Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I'm 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 it's 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 doesn't 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

  • Administrators
Posted

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?

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

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 it's recursively calling itself for each directory it's hard to keep track of how deep the recursions are going.......

 

On my c: It's 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.

Posted
Also, just commented out the check files routine, and it's listing the directory structure correctly, so maybe the ammount of calls to that is filling the callstack?
Posted
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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...