Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

file exists by file name pattern

Tags:

c#

.net

.net-2.0

I am using:

File.Exists(filepath) 

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

For example: the file could be

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

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

like image 551
JL. Avatar asked Jul 29 '09 10:07

JL.


Video Answer


1 Answers

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 } 
like image 171
monkey_p Avatar answered Sep 28 '22 00:09

monkey_p