List all files in a folder and its subfolders with linq

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));
}

Leave a reply