获取所有子目录仅包含文件 [英] Get all sub directories that only contain files

查看:240
本文介绍了获取所有子目录仅包含文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个路径,我想列出其下子目录,每个子目录中不包含任何其他目录。 (只有那些不包含文件夹的子目录,但只有文件。)

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?

推荐答案

这是我的理解是要列出以下只包含文件的指定路径中的子目录。

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

这篇关于获取所有子目录仅包含文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆