0

I know I can use

 Directory.GetFiles(sourceDirectory, pattern);

To get ALL the files with a particular pattern. However, I'm curious as to how would one get only the files wanted (i.e. from a list of some sort) with that same pattern?

dbugger
  • 15,868
  • 9
  • 31
  • 33
user1789573
  • 515
  • 2
  • 8
  • 23
  • Possible duplicate of [Can you call Directory.GetFiles() with multiple filters?](http://stackoverflow.com/questions/163162/can-you-call-directory-getfiles-with-multiple-filters) – pmeyer Feb 18 '16 at 16:59
  • i'm not really looking for filters, per say. I'd be looking for something like the following: Directory.GetFiles(sourceDirectory, pattern, listOfFilesToFind); – user1789573 Feb 18 '16 at 17:55

2 Answers2

0

Dont think you can do straight out of GetFiles, you can surely filter them though....

private static string[] GetFiles(string sourceFolder, string filters, System.IO.SearchOption searchOption, List<string> fileNames )
        {
            return System.IO.Directory.GetFiles(sourceFolder, filters, searchOption).Where(fileNames.Contains).ToArray();
        }
pmeyer
  • 890
  • 7
  • 31
0
string[] filePaths = filesToReturn.SelectMany(f => Directory.GetFiles(sourceDirectory, f)).ToArray();
Remi Guan
  • 21,506
  • 17
  • 64
  • 87
user1789573
  • 515
  • 2
  • 8
  • 23