参考链接 点击打开链接
public class DocumentTool
{
//检测文件目录是否存在
public static bool IsExistDirectory (string directoryPath)
{
return Directory.Exists (directoryPath);
}
//检测文件是否存在
public static bool IsExistFile (string filePath)
{
return File.Exists (filePath);
}
//检测指定目录是否为空
public static bool IsEmptyDirectory (string directoryPath)
{
try {
string[] fileNames = Directory.GetFiles (directoryPath);
if (fileNames.Length > 0) {
return false;
}
string[] directoryNames = Directory.GetDirectories (directoryPath);
return directoryNames.Length <= 0;
} catch {
return false;
}