获取文件夹中的ASP.NET的目录里面算 [英] Get Folder count inside a directory in ASP.NET

查看:86
本文介绍了获取文件夹中的ASP.NET的目录里面算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望得到的文件夹(子文件)在asp.net父文件夹里的数目。

I want to get the number of folders (sub folders) inside a parent folder in asp.net.

我试过 INT directoryCount =使用Server.Mappath(〜/资料夹/文件夹2 /)长度;

但没有得到正确的值。

推荐答案

使用 DirectoryInfo.GetDirectories 方法获取目录和指望他们喜欢的:

Use DirectoryInfo.GetDirectories method to get the directories and count them like:

DirectoryInfo di = new DirectoryInfo(Server.MapPath("~/folder1/folder2/"));
DirectoryInfo[] diArr = di.GetDirectories();

int count = dirArr.Length; //Total directories under the folder

以上将返回你的路径下的子目录,它不是递归的,如果你想找到递归所有的目录,然后使用重载的 DirectoryInfo.GetDirectories方法(String,SearchOption)

DirectoryInfo[] diArr = di.GetDirectories(Server.MapPath("~/folder1/folder2/"),
                                          SearchOption.AllDirectories);

这篇关于获取文件夹中的ASP.NET的目录里面算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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