C# 检查文件夹是否存在 - 使用 Directory.Exists() 方法
在 C# 中判断文件夹是否存在,可以使用 'Directory.Exists()' 方法。可以按照以下的代码示例来判断文件夹是否存在:
using System.IO;
string folderPath = @"C:\example\folder";
if (Directory.Exists(folderPath))
{
Console.WriteLine('文件夹存在');
}
else
{
Console.WriteLine('文件夹不存在');
}
在上面的代码中,我们首先定义了一个文件夹路径 'folderPath'。然后使用 'Directory.Exists()' 方法来判断该文件夹是否存在。如果存在,输出'文件夹存在',否则输出'文件夹不存在'。
原文地址: https://www.cveoy.top/t/topic/qbr6 著作权归作者所有。请勿转载和采集!