Linq Collecting Files Names Recursively
I use this snippet of code to gather paths off the hard-drive. Same pattern works for many other tree-traversals.
public static IEnumerable<string> Files(
this string root, Func<string, bool> accept)
{
return
Directory.GetFiles(root).Where(accept)
.Concat(
Directory.GetDirectories(root)
.SelectMany(d => d.Files(accept)));
}
As an extensions it works this way:
@"\Sumblime 2\Packages".Files(
s => s.EndsWith("tmLanguage");
Cheers
Written by Lucas Caballero
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#