1

I want to get a file with multiple extensions with recursion on C#.

This is what I tried:

public static IEnumerable<FileInfo> GetFilesByExtensions(this DirectoryInfo dir, params string[] extensions)
{
    if (extensions == null)
        throw new ArgumentNullException("extensions");

    IEnumerable<FileInfo> files = dir.EnumerateFiles();

    return files.Where(f => extensions.Contains(f.Extension));
}

And noticed that this not used this return files only from TopDirectoryOnly. I try this modification:

IEnumerable<FileInfo> files = dir.EnumerateFiles("*.*", SearchOption.AllDirectories);

But this did not help. Do you have any suggestions? Thanks.

fatihyildizhan
  • 8,614
  • 7
  • 64
  • 88
user1860934
  • 417
  • 2
  • 9
  • 22
  • 1
    Does this answer your question? [Method to get all files within folder and subfolders that will return a list](https://stackoverflow.com/questions/14305581/method-to-get-all-files-within-folder-and-subfolders-that-will-return-a-list) – Sinatr Apr 20 '21 at 10:14
  • Yes, tanks a lot – user1860934 Apr 20 '21 at 10:39

0 Answers0