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);