手机
当前位置:查字典教程网 >编程开发 >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文件和css文件的引用?

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

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

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

asp.net通过配置文件连接Access的方法

asp.net 备份和恢复数据库的方法

asp.net中List的使用方法

asp.net Web Services上传和下载文件(完整代码)第1/2页

Asp.net给站点某目录增加Aspnet用户

asp.net为网页动态添加关键词的方法

精品推荐
分类导航