Click here to Skip to main content
16,014,662 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Friends please give me some sample code that shows how to search a drive for a specific folder and list all the folder with same name in a listview with path.
Posted
Comments
ZurdoDev 20-Nov-13 11:09am    
google has some and there is also a search feature on this site.

1 solution

You need to start searching at the top level of each drive and use the Directory.GetDirectories method to retrieve a list of directories that you want to compare. You will use each of these directories to keep searching for the matching directories. In pseudo-code, your algorithm will look something like this:
Function MatchDirectory - pass in a path to a folder (e.g. C:\)
  Get the array of directories under this folder using <code>Directory.GetDirectories</code> using the folder path you passed in.
  If there are no directories, return out of this function
  For each entry in the directory array
    Get the directory name (a simple search from the end of the string to the previous \ will do it).
    If the directory name matches the one you're searching for, add the full name to your ListView.
    Call MatchDirectory, passing in the current directory entry
  End 
End
 
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