Computer >> Máy Tính >  >> Lập trình >> C#

Làm cách nào để tìm tệp bằng C #?

Sử dụng GetDirectories trong C # để nhận danh sách thư mục con xuất hiện đầu tiên -

Directory.GetDirectories

Bây giờ lặp qua các thư mục đó và lặp lại quy trình cho thư mục con.

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