博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C#两种方式获取指定文件夹下所有子目录及文件
阅读量:7124 次
发布时间:2019-06-28

本文共 3264 字,大约阅读时间需要 10 分钟。

 

/****************************************     * 函数名称:GetFoldAll(string Path)     * 功能说明:获取指定文件夹下所有子目录及文件(树形)     * 参 数:Path:详细路径     * 调用示列:     * string strDirlist = Server.MapPath("templates");     * this.Literal1.Text = EC.FileObj.GetFoldAll(strDirlist);     *****************************************/    ///      /// 获取指定文件夹下所有子目录及文件     ///      /// 详细路径     public static string GetFoldAll(string Path)    {        string str = "";        DirectoryInfo thisOne = new DirectoryInfo(Path);        str = ListTreeShow(thisOne, 0, str);        return str;    }    ///      /// 获取指定文件夹下所有子目录及文件函数     ///      /// 指定目录     /// 默认起始值,调用时,一般为0     /// 用于迭加的传入值,一般为空     /// 
public static string ListTreeShow(DirectoryInfo theDir, int nLevel, string Rn)//递归目录 文件 { DirectoryInfo[] subDirectories = theDir.GetDirectories();//获得目录 foreach (DirectoryInfo dirinfo in subDirectories) { if (nLevel == 0) { Rn += "├"; } else { string _s = ""; for (int i = 1; i <= nLevel; i++) { _s += "│ "; } Rn += _s + "├"; } Rn += "" + dirinfo.Name.ToString() + "
"; FileInfo[] fileInfo = dirinfo.GetFiles(); //目录下的文件 foreach (FileInfo fInfo in fileInfo) { if (nLevel == 0) { Rn += "│ ├"; } else { string _f = ""; for (int i = 1; i <= nLevel; i++) { _f += "│ "; } Rn += _f + "│ ├"; } Rn += fInfo.Name.ToString() + "
"; } Rn = ListTreeShow(dirinfo, nLevel + 1, Rn); } return Rn; } /**************************************** * 函数名称:GetFoldAll(string Path) * 功能说明:获取指定文件夹下所有子目录及文件(下拉框形) * 参 数:Path:详细路径 * 调用示列: * string strDirlist = Server.MapPath("templates"); * this.Literal2.Text = EC.FileObj.GetFoldAll(strDirlist,"tpl",""); *****************************************/ /// /// 获取指定文件夹下所有子目录及文件(下拉框形) /// /// 详细路径 ///下拉列表名称 ///默认选择模板名称 public static string GetFoldAll(string Path, string DropName, string tplPath) { string strDrop = ""; } /// /// 获取指定文件夹下所有子目录及文件函数 /// /// 指定目录 /// 默认起始值,调用时,一般为0 /// 用于迭加的传入值,一般为空 /// 默认选择模板名称 ///
public static string ListTreeShow(DirectoryInfo theDir, int nLevel, string Rn, string tplPath)//递归目录 文件 { DirectoryInfo[] subDirectories = theDir.GetDirectories();//获得目录 foreach (DirectoryInfo dirinfo in subDirectories) { Rn += "

转载地址:http://tchel.baihongyu.com/

你可能感兴趣的文章
百度API的经历,怎样为多个点添加带检索功能的信息窗口
查看>>
在windows下通过samba的共享编辑过的openwrt的样式文件无法访问的解决办法
查看>>
总结: 在fc23中, 安装音频mp3 视频flv 的播放插件其实很简单, 只要一步就可以了: dnf install gstreamer1-libav...
查看>>
Filter中实现页面转发
查看>>
c++ vector
查看>>
python中selenium操作下拉滚动条方法汇总
查看>>
Skyline中加载WMTS地图
查看>>
Windows下的上帝模式
查看>>
浏览器的 bfcache 特性
查看>>
一款集JS格式化,JS压缩,解压,CSS格式化,压缩的工具整合
查看>>
python报错:AttributeError: 'builtin_function_or_method' object has no attribute 'strftime'
查看>>
[洛谷P1993]小K的农场
查看>>
转载:Service Mesh:重塑微服务市场--敖小剑
查看>>
day26 Python __getattribute__
查看>>
python装饰器
查看>>
bzoj 3196: Tyvj 1730 二逼平衡树
查看>>
Linux学习第三篇之Linux常用命令——命令格式与目录处理命令ls
查看>>
Unable to execute dex: method ID not in [0, 0xffff]: 65536
查看>>
【人生】不管你挣多少, 钱永远是问题
查看>>
过河问题
查看>>