在做程序时经常会产生临时性文件,下边有一个转自他人的一个删除指定文件夹下临时文件的方法
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
private void deletefiles(System.IO.DirectoryInfo path)
{
foreach(System.IO.DirectoryInfo d in path.GetDirectories())
{
deletefiles(d);
}
foreach(System.IO.FileInfo f in path.GetFiles())
{
f.Delete();
}
} protected void Button1_Click1(object sender, EventArgs e)
{
System.IO.DirectoryInfo path = new System.IO.DirectoryInfo(Server.MapPath("ChartImages"));
deletefiles(path);
Response.Write("<script language=javascript>window.alert('系统冗余文件清理成功!'); </script>");
}