Link to home
Start Free TrialLog in
Avatar of jjacksn
jjacksn

asked on

URGENT: How can you find the directory of a file?

What is the easiest way to search all drives of a computer for a file name and return a list of all the directories where that file name occrus?  
Avatar of mogun
mogun

You got to loop through the directory structure...No easy way out i guess... :)
Here is an example, but it's VB.NET: http://www.developerfusion.com/show/4264/
And here you can see a powerful example to search by filter or regular expression: http://www.personalmicrocosms.com/html/filesearch.html
ASKER CERTIFIED SOLUTION
Avatar of randydandy
randydandy

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This code will search all accessible drives on the computer, looking for the filename entered by the user.

GetDirs is called for each drive as the path, the GetDirs method will then recursively search each directory on the drive, adding any directories that contain the file to the directories StringCollection.

Once all drives have been searched, the directories StringCollection will contain a list of all the directories on all the drives that contain the filename entered by the user.