文件存在,按文件名模式 [英] file exists by file name pattern

查看:193
本文介绍了文件存在,按文件名模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的:

File.Exists(filepath)

我想这样做是串换了这一点,一个模式,因为文件名更改的第一部分。

What I would like to do is swop this out for a pattern, because the first part of the filename changes.

例如:文件可以是

01_peach.xml
02_peach.xml
03_peach.xml

如何检查文件是否存在基于某种搜索模式?

How can I check if the file exists based on some kind of search pattern?

推荐答案

您可以做一个目录列表用图案来检查文件

You can do a directory list with a pattern to check for files

string[] files = System.IO.Directory.GetFiles(path, "*_peach.xml", System.IO.SearchOption.TopDirectoryOnly);
if (files.Length > 0)
{
    //file exist
}

这篇关于文件存在,按文件名模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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