Click here to Skip to main content
15,881,413 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can someone please provide an example on how to search your entire computer by using recrusion?......

My scanner scans names by using a text file loaded into the resource but currently it only scans one level of the directory selected in the combobox. How can I use recrusion to scan the subfolders of C:\ or D:\ or E:\ when the user selects the root dir from the combobox?

any advice at this point will be appriaciated as I have looked every where to only find partial examples, I need a full example and maybe a small discription to learn the steps of recrusion.
Posted
Updated 17-Oct-10 13:04pm
v2

1 solution

I don't think I need to provide any actual code here but the steps go like this:

void RecurseFolder( scan_folder )
{
  for each file in the scan_folder
  {
    //Do whatever you need
  }

  for each new_folder in the scan_folder
  {
    //Call ourself with the new folder
    RecurseFolder( new_folder )
  }
}


You see the function calls itself again for each sub folder it finds in the root folder, so it works its way through all of your directories in basically a depth first search.

If you've never done anything with recursion before I understand that it can seem a little confusing but it's really quite simple.
 
Share this answer
 

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