C# 如何判断文件夹是否存在

以下代码检查目录是否存在,只有当目录存在时才删除。

string root = @"C:\Temp";

if (Directory.Exists(root))

{
   Directory.Delete(root);
}
c#中如何检查文件夹是否存在

.NET Framework类库中的System.io.Directory类提供了创建,复制,移动和删除目录和子目录的静态方法。
在使用目录类之前,必须导入system.io命名空间。

using System.IO; 

在C#中检查目录是否存在

directory.Exist方法检查指定的目录是否存在。

日期:2020-04-11 22:50:16 来源:oir作者:oir