Directory.GetFiles search param

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 -
 
J

Joep

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)
 
C

Chris Rolon

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 -
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top