List all files in a folder and its subfolders with linq

  • .NET

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

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 on Twitter or by email!

Follow me:
Enjoy this blog?Buy Me A CoffeeDonate with PayPal