Alex Rivera | Logout

C# Search for subdirectory (not for files)

Asked 2010-04-01T14:00:51.597
9

Every example I see seems to be for recursively getting files in subdirectories uses files only. What I'm trying to do is search a folder for a particular subdirectory named "xxx" then save that path to a variable so I can use it for other things.

Is this possible without looping through all the directories and comparing by name?

Edit
Report

2 Answers

1

First of all, "No, it is not possible without looping through all the directories and comparing by name".

I believe your real question is "Is there an existing API which will handle looping through all the directories and comparing by name for me?"

Yes, there is. It's called Directory.Exists():

var xxxPath = Path.Combine(parentFolder, "xxx");
if (Directory.Exists(xxxPath))
    savedPath = xxxPath;
answered 2010-04-01T14:14:40.247
0

Yes, I believe that the only available solution (short of third party libraries) is a recursive search for the directory via name comparison.

answered 2010-04-01T14:04:24.120

Your Answer