Get all sub directories that only contain files

前端 未结 4 1613
说谎
说谎 2020-12-11 17:36

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

4条回答
  •  不知归路
    2020-12-11 17:45

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


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

提交回复
热议问题