Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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 folders, but only files.)

Any smart way to do so?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
146 views
Welcome To Ask or Share your Answers For Others

1 Answer

It is my understanding that you want to list the subdirectories below a given path that contain only files.


static IEnumerable<string> GetSubdirectoriesContainingOnlyFiles(string path)
{
  return from subdirectory in Directory.GetDirectories(path, "*", SearchOption.AllDirectories)
         where Directory.GetDirectories(subdirectory).Length == 0
        select subdirectory;
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...