代码如下:
protected void Page_Load(object sender, EventArgs e)
{
//指定目标文件夹
string directory = @"C:\Windows\Microsoft.NET\Framework\v3.5";
IterationFile(directory);
}
private void IterationFile(string path)
{
DirectoryInfo di = new DirectoryInfo(path);
//输出当前目录。
Response.Write(di.ToString() + "<br />");
//取得当前目录中所有文件
FileInfo[] fiArray = di.GetFiles();
//循环每一个文件
for (int i = 0; i < fiArray.Length; i++)
{
Response.Write(fiArray[i].ToString() + "<br/>");
}
//每个目录结束,写一空行。
Response.Write("----------------------------------------------------------------------------<br/>");
//取得当前目录中所有子目录
DirectoryInfo[] diArray = di.GetDirectories();
//循环每一个目录
for (int j = 0; j < diArray.Length; j++)
{
IterationFile(diArray[j].FullName);
}
}