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

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

问题描述

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

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.

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

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

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

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