如何检查是否一个文件夹中的存在? [英] How to check if a file exists in a folder?

查看:176
本文介绍了如何检查是否一个文件夹中的存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要检查,如果一个XML文件的文件夹中存在。

I need to check if an xml file exists in the folder.

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

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

Is this the best way to check a file exists in the folder.

我需要检查只是一个XML文件present

I need to check just an xml file is present

推荐答案

这是一个方法,如果任何XML的文件存在文件夹中,是的。

This is a way to see if any XML-files exists in that folder, yes.

要检查特定文件使用<一个href=\"http://msdn.microsoft.com/en-us/library/system.io.file.exists.aspx\"><$c$c>File.Exists(path),它会返回一个布尔值,表示wheter在路径该文件存在。

To check for specific files use File.Exists(path), which will return a boolean indicating wheter the file at path exists.

这篇关于如何检查是否一个文件夹中的存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆