Chia sẻ

Hello friends !

Now, we will learn How to Get Sub Directories in C# ?. The GetDirectories method of the Directory class loads all the subdirectories of a directory. To get all subdirectories, we can read subdirectories recursively.

public void GetSubDirectories()
{
    string root = @"C:Temp";
    // Get all subdirectories
    string[] subdirectoryEntries = Directory.GetDirectories(root);
    // Loop through them to see if they have any other subdirectories
    foreach (string subdirectory in subdirectoryEntries) 
    {
        LoadSubDirs(subdirectory);
    }
}

private void LoadSubDirs(string dir)
{
    Console.WriteLine(dir);
    string[] subdirectoryEntries = Directory.GetDirectories(dir);
    foreach (string subdirectory in subdirectoryEntries)
    {
        LoadSubDirs(subdirectory);
    }
}

I wish you success, please leave a comment below, we will answer all your questions.

GoodLuck !!!

 

 

 

ĐĂNG KÝ MUA HÀNG

    Email (*)

    Điện thoại (*)

    Tên sản phẩm/Dịch vụ:


    Chia sẻ
    Xem thêm  [C#] How to use File.Open Method

    Trả lời

    Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *