Click here to Skip to main content
15,891,409 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I am having an algorithm like:

Search(path)
{
      for each d as directory in path
             Search(d)  //Recurse

      for each f as file in path
           //do something with f

}



Here the main recursion is due to search in all sub directories. Can this be made iterative one ?
Any help will be nice.

Thanks,
Dan
Posted
Updated 5-Dec-10 23:40pm
v2

1 solution

Why don't you use the DirectoryInfo object, retrieve all file names (including the sub-folders), and just do one iteration through all of the returned file names...
 
Share this answer
 
Comments
Dan Suthar 6-Dec-10 5:47am    
suppose mine is C drive then DirectoryInfo on C Drive will give me all dirs and files in it but will it give all sub files/folders ? If so then in short it should list all files eventually present in C Drive. Can u give me an example ?

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