asp.net|递归|显示
private void Page_Load(object sender, System.EventArgs e)
{
string strDirlist="目录绝对路径";
DirectoryInfo thisOne=new DirectoryInfo(strDirlist);
Response.Write("<pre>");
ListTreeShow(thisOne,0);
Response.Write("</pre>");
}
private void ListTreeShow(DirectoryInfo theDir,int nLevel)//递归目录 文件
{
DirectoryInfo[] subDirectories=theDir.GetDirectories();//获得目录
//for(int i=0;i<subDirectories.Length;i++)
foreach (DirectoryInfo dirinfo in subDirectories)
{
Response.Write("深度="+nLevel+"
");
Response.Write("文件夹:"+dirinfo.Name+"\r\n
");
FileInfo[] fileInfo =dirinfo.GetFiles(); //目录下的文件
//FileInfo[] fileInfo=dirinfo.GetFiles("*.dwt");//获取指定类型的文件
foreach (FileInfo fInfo in fileInfo)
{
Response.Write("文件="+fInfo.Name.ToString()+"\r\n\n");
}
ListTreeShow(dirinfo,nLevel+1);
}
}