I have a path and I want to list the subdirectories under it, where each subdirectory doesn\'t contain any other directory. (Only those subdirectories which don\'t contain f
Based on Havard's answer, but a little shorter (and maybe slightly easier to read because it uses !Subdirs.Any() instead of Subdirs.Length == 0):
static IEnumerable GetSubdirectoriesContainingOnlyFiles(string path)
{
return Directory.GetDirectories(path, "*", SearchOption.AllDirectories)
.Where( subdir => !Directory.GetDirectories(subdir).Any() );
}
Also note, that this requires using System.Linq; to work, since it uses the LINQ query language. (And of course using System.IO; for the Directory class :))