Directory.GetFiles search param

  • Thread starter Thread starter John Smith
  • Start date Start date
J

John Smith

Hello all:

I am trying to search for more than one extension in a directory at the
same time with the following code:

string[] files = Directory.GetFiles(sDir, "*.doc*.dot");

However, this does not work nor does something like this:

string[] files = Directory.GetFiles(sDir, "*.doc, *.dot");

I can search for each individually but that is rather inefficient. Is
there a way to search for multiple extensions at once?

Thanks,

- John -
 
sure, "*.*" and then in the loop check the extension of the file against
those you are interested in (you can put those extensions in a string and
use indexof but have a good look at what getfiles does, it might surprise
you)
 
Get Files will not do what you want. Why not write a method that takes a
variable number of string arguments that are the extensions, retrieves and
merges the results from calls to GetFiles on each string. That should be
trivial.

--

Chris Rolon

This posting is provided "AS IS" with no warranties, and confers no rights.

Joep said:
sure, "*.*" and then in the loop check the extension of the file against
those you are interested in (you can put those extensions in a string and
use indexof but have a good look at what getfiles does, it might surprise
you)


John Smith said:
Hello all:

I am trying to search for more than one extension in a directory at the
same time with the following code:

string[] files = Directory.GetFiles(sDir, "*.doc*.dot");

However, this does not work nor does something like this:

string[] files = Directory.GetFiles(sDir, "*.doc, *.dot");

I can search for each individually but that is rather inefficient. Is
there a way to search for multiple extensions at once?

Thanks,

- John -
 
Back
Top