Answer the question
In order to leave comments, you need to log in
Why doesn't it return what I need C#?
public static string Searcher(string path, string pattern)
{
var parts = new List<DirectoryInfo> { };
DirectoryInfo dir = new DirectoryInfo(path);
try
{
DirectoryInfo[] dirs = dir.GetDirectories();
foreach (DirectoryInfo di in dirs)
{
parts.Add(di);
}
}
catch { };
foreach (DirectoryInfo part in parts.ToList())
{
if(part.ToString().Contains(pattern) == true)
{
return part.ToString();
}
else
{
Searcher(part.ToString(), pattern);
}
}
return null;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question