手机
当前位置:查字典教程网 >编程开发 >asp.net教程 >asp.net遍历目录文件夹和子目录所有文件
asp.net遍历目录文件夹和子目录所有文件
摘要:复制代码代码如下:usingSystem;usingSystem.Collections.Generic;usingSystem.Text;...

复制代码 代码如下:

usingSystem;

usingSystem.Collections.Generic;

usingSystem.Text;

usingSystem.IO;

usingSystem.Threading;

namespacecopefile

{

classProgram

{

staticvoidMain(string[]args)

{

stringtestDir="e:/xunlei/";

listFiles(testDir,0);

Console.ReadKey();

}

publicstaticvoidlistFiles(stringdir,intlevel)

{

//阿会楠练习作品,程序多有参考

try

{

//获取文件列表

string[]files=Directory.GetFiles(dir);

StringpreStr="";

for(inti=0;i<level;i++)

{

preStr+="";

}

foreach(stringfinfiles)

{

if(f.LastIndexOf("")==-1)

{

Console.WriteLine(preStr+f.Substring(f.LastIndexOf("/")+1));

}

else

{

Console.WriteLine(preStr+f.Substring(f.LastIndexOf("")+1));

}

}

//获取目录列表

string[]dirs=Directory.GetDirectories(dir);

foreach(stringdindirs)

{

if(d.LastIndexOf("")==-1)

{

Console.WriteLine(preStr+d.Substring(d.LastIndexOf("/")+1));

}

else

{

Console.WriteLine(preStr+d.Substring(d.LastIndexOf("")+1));

}

if(Directory.Exists(d))

{

listFiles(d,level+1);

}

}

}

catch(Exceptionex)

{

Console.WriteLine(ex.Message);

}

}

}

}

【asp.net遍历目录文件夹和子目录所有文件】相关文章:

asp.net动态添加js文件调用到网页的方法

asp.net neatUpload 支持大文件上传组件

asp.net 大文件上传控件

asp.net后台如何动态添加JS文件和css文件的引用?

asp.net Xml绑定到数据控件的具体实现

asp.net保存远程图片的代码

asp.net 文件下载实现代码

asp.net Hashtable 遍历写法

收藏的asp.net文件上传类源码

Asp.net(C#)文件操作函数大全

精品推荐
分类导航