在C#中,可以使用Directory.Exists()
方法来检查指定的目录是否存在。该方法返回一个布尔值,表示目录是否存在。
以下是使用Directory.Exists()
方法的示例:
string path = @"C:\Example\Directory";
if (Directory.Exists(path))
{
Console.WriteLine("目录存在");
}
else
{
Console.WriteLine("目录不存在");
}
在上面的示例中,我们首先指定了一个目录路径path
。然后,使用Directory.Exists()
方法检查该目录是否存在。如果存在,我们输出"目录存在";如果不存在,我们输出"目录不存在"。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:C#中Directory.Exists()方法的作用是什么