获取所有子目录从给定路径 [英] Get all sub directories from a given path

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

问题描述

我有一些路径,我想从它只是子目录路径得到(我的意思只是说在他们那里没有发现其它目录中的文件路径)。

I have some path , and i want to get from it only the subdirectories paths (i mean only paths that under them where not found another directories 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天全站免登陆