Answer the question
In order to leave comments, you need to log in
I did a method that searches for a folder, but it does not browse the folders to the end, how can I fix this?
There is a folder I need, its path is C:\folder\folder\folder\folder\the folder I
need. But the method does not scan to the end, that is, it displays C:\folder\folder\folder\folder
public static void Searcher(string path,string pattern)
{
var parts = new List<DirectoryInfo> {};
DirectoryInfo di = new DirectoryInfo(path);
DirectoryInfo[] diarr = di.GetDirectories();
bool isend = false;
string mypath;
foreach (DirectoryInfo d in diarr)
{
if (d.ToString().Contains(pattern) == true)
{
Console.WriteLine("НАЙДЕНООООООООООООООООООООООООООООООО путь ||" + d);
isend = true;
mypath = d.ToString();
}
try
{
diarr = d.GetDirectories();
}
catch { }
parts.Add(d);
while (isend == false )
{
foreach (DirectoryInfo dir in diarr)
{
if (dir.ToString().Contains(pattern) == true)
{
Console.WriteLine("НАЙДЕНООООООООООООООООООООООООООООООО путь ||" + dir);
isend = true;
mypath = dir.ToString();
}
try
{
diarr = dir.GetDirectories();
Console.WriteLine(dir);
}
catch (Exception) { Console.WriteLine("err"); }
}
if (diarr.Length == 0)
{
break;
}
}
if (isend == true)
{
break;
}
}
}
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