C#遍历一个文件夹下的所有文件夹
- string thePath = "../../Upload/Star/";
- thePath = Server.MapPath(thePath);//得到文件绝对路径
- System.IO.DirectoryInfo d = new System.IO.DirectoryInfo(thePath);
- System.IO.DirectoryInfo[] ds = d.GetDirectories("*.*", System.IO.SearchOption.TopDirectoryOnly);
- foreach (System.IO.DirectoryInfo var in ds)
- {
- //路径全称
- Response.Write(var.FullName + "<br/>");//遍历文件夹下面的文件夹
- //仅文件名称
- Response.Write(var.Name + "<br/>");
- }