Use this:
Directory.GetDirectories(root, directoryName, SearchOption.AllDirectories);
where root is the path to run and directoryName is the specific name you are looking for. You can use .Any()
to check if it exists and .First()
to get the first one.
edited after comment pinkfloydx33
Yes, EnumerateDirectories will be better. Sorry, I'm stuck in .net 3.5 mode at the moment: D, so you are looking for:
Directory.EnumerateDirectories(root, directoryName, SearchOption.AllDirectories).FirstOrDefault();
and checking for zero.
source
share