Locating files using wildcards

Hi,

I'm trying to locate a file by wildcard (I know the path, I'm just searching for a fine inside that directory), but I can't seem to find a way to do this. For example, say I have the following files:

file1.txt
file2.txt

I want to be able to locate them with just looking for "file*.txt" or something similar with regular expressions. However, I don't want to have more than one match, so the above example would either fail or somehow indicated that there was more than one match.

Thanks!



Answer this question

Locating files using wildcards

  • setrio

    Thanks thats exactly what I needed
  • farkbert

    Hi,

    I'm not sure if this is what you're looking for, but just for an idea:

    using System.IO;

    ...

    string[] files = Directory.GetFiles(@"c:\myfolder\", "file*.txt", SearchOption.TopDirectoryOnly);
    int fileCount = files.Length;

    No regular expressions, just file wild cards here... Hope it helps anyway...

    Andrej



  • Locating files using wildcards