我需要检查文件夹中是否存在 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/