tags:

views:

1785

answers:

2

Using C# .net v2.

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?

+9  A: 

You can do a direcoty list to check for files

string[] files = Directory.GetFiles(path, "*_peach.xml",SearchOption.TopDirectoryOnly);
if (files.Length > 0)
{
    //file exist
}
monkey_p
you accepted that answer faster than you could check it. What gives??
Mitch Wheat
sigh, out typed me :)
tim
+2  A: 

Get a list of all matching files using System.IO.DirectoryInfo.GetFiles()

Also see SO Questions:

Is there a wildcard expansion option for .net apps?

How do I check if a filename matches a wildcard pattern

and many others...

Mitch Wheat