获取子文件夹数 [英] Get subfolders count

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

问题描述

如何获取服务器端可用目录的子文件夹数.

根据子文件夹的名称,我需要填充树形视图.这样我就可以动态填充树视图,而不是静态显示树视图.

请帮助我.

How to get the subfolders count of the directory available at server side.

depends on the subfolders names, I need to fill the tree view. so that instead of static display of treeview, I can make it dynamic filling of the treeview.

Help me please.

推荐答案

使用System.IO命名空间中可用的DirectoryInfo类


Use DirectoryInfo class available in System.IO namespace


DirectoryInfo info = new DirectoryInfo("C:\\MySpace");
            IEnumerable<directoryinfo> var =    info.EnumerateDirectories();</directoryinfo>



var将包含有关子目录的所有信息



var would contain all the information about sub directories


在这里,...获取子文件夹计数的示例代码:
Here you go... sample code for getting the subfolder count:
//WAY 1
int iCount =0;
DirectoryInfo diSource = new DirectoryInfo(sourceDirectory);
DirectoryInfo[] disSubFolders = diSource.GetDirectories();
iCount = disSubFolders.Length;

//WAY 2
int iCount =0;
DirectoryInfo diSource = new DirectoryInfo(sourceDirectory);
foreach (DirectoryInfo di in diSource) 
{
   iCount ++;   
   //Can do anything else too if needed. 
}


您好,感谢您的回复,我之前已经开发了相同的代码,该问题我能够获得该项目的根文件夹,但是我没有得到完整的路径.如何在没有服务器端文件夹完整路径的情况下读取子文件夹.
Hi Thanks for the response, I have developed the same code earlier, the problem I was able to get the root folder of the project, but I am not getting the complete path. How to read the subfolders without complete path of the folder at server side.


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

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