1

I want to search for all files ending .vcproj or .sln in a directory. It's not clear to me from the docs if searchPattern can specify multiple filters or if I'd have to run separate searches.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Mr. Boy
  • 60,845
  • 93
  • 320
  • 589
  • here's a link to similar question http://stackoverflow.com/questions/163162/can-you-call-directory-getfiles-with-multiple-filters – Dhawalk Jan 09 '13 at 15:25
  • 2
    @Dhawalk: Nice use of LINQ in the accepted answer of that question, though LINQ is not available in a .NET 2.0 environment. – Eric J. Jan 09 '13 at 15:26
  • my bad. I missed that.... thanks – Dhawalk Jan 09 '13 at 15:29
  • @Dhawalk: Still a good comment, because others that find this question might not be constrained to .NET 2. – Eric J. Jan 09 '13 at 16:35

2 Answers2

4

No, you can only specify one filter.

You can add the result of each search to a HashSet<string> to get a unique list of files matching both searches. A List<string> would not work in edge cases where two different wildcard search patterns can match the same file.

UPDATE

HashSet<T> is only available in .NET 3.5 and later. Since you are using 2.0, you could use a List<T>, but you should check if each item already exists before adding it.

Eric J.
  • 147,927
  • 63
  • 340
  • 553
1

For GetFiles() you can use 1 filter option. You shoul get them separately.

string[] file1 = System.IO.Directory.GetFiles(path, "*.vcproj");
string[] file2 = System.IO.Directory.GetFiles(path, "*.sln ");
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364