List all files in a folder and its subfolders with linq

 
 
  • Gérald Barré

How to list all files in a folder and all its subfolders into a single LINQ request?

C#
private static IEnumerable<string> GetFiles(string path)
{
    return Directory.EnumerateFiles(path)
        .Concat(Directory.EnumerateDirectories(path).SelectMany(GetFiles));
}

Do you have a question or a suggestion about this post? Contact me!

Follow me:
Enjoy this blog?Buy Me A Coffee💖 Sponsor on GitHub