Patrick Matthews
asked on
Function needed to recursively search a directory for a named subdirectory
Normally I would just do this myself, but I am a bit pressed for time :)
I need a function that will locate a named subdirectory within a parent directory, and have as its
return value the path string to the subdirectory.
Here is an example.
Assume the following directories exist:
c:\Start here\Location 1\Team 1\Alice
c:\Start here\Location 1\Team 1\Ben
c:\Start here\Location 1\Team 1\Charlene
c:\Start here\Location 1\Team 2\David
c:\Start here\Location 1\Team 2\Ernie
c:\Start here\Location 1\Team 2\Frances
c:\Start here\Location 2\Team 3\George
c:\Start here\Location 2\Team 3\Harry
c:\Start here\Location 2\Team 3\Ivana
c:\Start here\Location 2\Team 4\John
c:\Start here\Location 2\Team 4\Karla
c:\Start here\Location 2\Team 4\Lance
c:\Start here\Location 3\Team 5\Mary
c:\Start here\Location 3\Team 5\Neville
c:\Start here\Location 3\Team 5\Opal
c:\Start here\Location 3\Team 6\Quentin
c:\Start here\Location 3\Team 6\Rachel
c:\Start here\Location 3\Team 6\Stephen
All of the people's folders exist somewhere in c:\Start here, or in one of the folder's "descendants".
I need a function to which I could pass arguments like "c:\Start here" and "Quentin", and then the function
would search recursively through c:\Start here and its descendants until it finds
c:\Start here\Location 3\Team 6\Quentin, and would return the string "c:\Start here\Location 3\Team 6\Quentin".
Thanks,
Patrick
I need a function that will locate a named subdirectory within a parent directory, and have as its
return value the path string to the subdirectory.
Here is an example.
Assume the following directories exist:
c:\Start here\Location 1\Team 1\Alice
c:\Start here\Location 1\Team 1\Ben
c:\Start here\Location 1\Team 1\Charlene
c:\Start here\Location 1\Team 2\David
c:\Start here\Location 1\Team 2\Ernie
c:\Start here\Location 1\Team 2\Frances
c:\Start here\Location 2\Team 3\George
c:\Start here\Location 2\Team 3\Harry
c:\Start here\Location 2\Team 3\Ivana
c:\Start here\Location 2\Team 4\John
c:\Start here\Location 2\Team 4\Karla
c:\Start here\Location 2\Team 4\Lance
c:\Start here\Location 3\Team 5\Mary
c:\Start here\Location 3\Team 5\Neville
c:\Start here\Location 3\Team 5\Opal
c:\Start here\Location 3\Team 6\Quentin
c:\Start here\Location 3\Team 6\Rachel
c:\Start here\Location 3\Team 6\Stephen
All of the people's folders exist somewhere in c:\Start here, or in one of the folder's "descendants".
I need a function to which I could pass arguments like "c:\Start here" and "Quentin", and then the function
would search recursively through c:\Start here and its descendants until it finds
c:\Start here\Location 3\Team 6\Quentin, and would return the string "c:\Start here\Location 3\Team 6\Quentin".
Thanks,
Patrick
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you! works just as I needed it to.
Regards,
Patrick
Regards,
Patrick
ASKER
angelIII,
The only change of any substance was to change:
if subfolder.name = searchname then
to:
If StrComp(subfolder.Name, SearchName, vbTextCompare) = 0 Then
thus making the comparison not case-sensitive (assuming the default text mode is binary; if I used Option Compare Text
then it's moot).
Regards,
Patrick
The only change of any substance was to change:
if subfolder.name = searchname then
to:
If StrComp(subfolder.Name, SearchName, vbTextCompare) = 0 Then
thus making the comparison not case-sensitive (assuming the default text mode is binary; if I used Option Compare Text
then it's moot).
Regards,
Patrick
ASKER
criteria, shame on me.
Patrick