侧梦美人,t8002,飞龙在天4
using system;
using system.collections.generic;
using system.text;
using system.io;
using system.threading;
namespace copefile
{
class program
{
static void main(string[] args)
{
string testdir = "e:/xunlei/";
listfiles(testdir,0);
console.readkey();
}
public static void listfiles(string dir, int level)
{
//阿会楠练习作品,程序多有参考
try
{
//获取文件列表
string[] files = directory.getfiles(dir);
string prestr = "";
for (int i = 0; i < level; i++)
{
prestr += " ";
}
foreach (string f in files)
{
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 (string d in dirs)
{
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 (exception ex)
{
console.writeline(ex.message);
}
}
}
}
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!!
点击进行留言回复
网友评论