c# - 如何检查文件夹中是否存在文件?

标签 c# xml file fileinfo

我需要检查文件夹中是否存在 xml 文件。

DirectoryInfo di = new DirectoryInfo(ProcessingDirectory);
FileInfo[] TXTFiles = di.GetFiles("*.xml");
if (TXTFiles.Length == 0)
{
    log.Info("no files present")
}

这是检查文件夹中是否存在文件的最佳方式吗。

我只需要检查一个 xml 文件是否存在

最佳答案

这是一种查看该文件夹中是否存在任何 XML 文件的方法,是的。

要检查特定文件,请使用 File.Exists(path) ,它将返回一个 bool 值,指示 path 中的文件是否存在。

关于c# - 如何检查文件夹中是否存在文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7385251/

相关文章:

c# - 右对齐字符串格式的货币

c# - DateTime.TryParse() 和 DateTime.TryParseExact() 无法在 linux/macos 上解析日期并在 windows 上正常工作

php - 如何让 DOMDocument 在 PHP 中写 standalone=yes?

java - 检查文件是否存在,如果存在,则不创建新文件并追加

c# - Windows 8 C# 从多个地方访问文件时出现拒绝访问错误

c# - 如何在 Entity Framework Code First 中删除一个表?

javascript - 如何使用 Ajax 按用户提供的值搜索 xml 文档

python - 使用 Jenkins 可视化旧的 JUnit XML 文件

c - 为什么“while(!feof(file))”总是错误的?

Python:将大型网页保存到文件