Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> C#

Chương trình C# kiểm tra thư mục có tồn tại

Directory.Exists(path) trả về true nếu thư mục tồn tại.

Ví dụ

using System.IO;
using System;

public class Program
{
    public static void Main()
    {
        if (Directory.Exists(@"C:\Amit"))
            Console.WriteLine("Thư mục Amit tồn tại!");
        else
            Console.WriteLine("Thư mục Amit không tồn tại!");
    }
}

Kết quả

Thư mục Amit không tồn tại!