Directory.Exists() checks if the specified folder exists.
The Directory.Exists() method is used to check if a specific folder exists. It takes a string parameter indicating the folder’s path and returns a boolean value – true if the folder exists, false if it does not.
Here is a sample code:
using System;
using System.IO;
class Program
{
static void Main()
{
string folderPath = @"C:\Temp"; // 指定文件夹路径
bool folderExists = Directory.Exists(folderPath); // 使用Directory.Exists()判断文件夹是否存在
if (folderExists)
{
Console.WriteLine("文件夹存在");
}
else
{
Console.WriteLine("文件夹不存在");
}
}
}
Note: When using Directory.Exists() to determine if a folder exists, you need to provide the full path of the folder.