How to find the file using C#?


Use the GetDirectories in C# to get a list of sub-folder that appears first −

Directory.GetDirectories

Now loop through those directories and repeat the process for the sub folder.

string path = @"d:/New/Myfile";
string[] myDir = Directory.GetDirectories(path, "xml", SearchOption.AllDirectories);
Console.WriteLine(myDir.Length.ToString());
foreach (string res in myDir)
Console.WriteLine(res);

Updated on: 22-Jun-2020

88 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements