1、說明
使用Directory類對指定文件夾下的今天或者更早日期之前的文件進行刪除。原文鏈接:http://www.cnblogs.com/lengzhan/p/6423943.html
2、代碼
//文件夾路徑
string strFolderPath = Server.MapPath("~") + "\\excel\\";
DirectoryInfo dyInfo = new DirectoryInfo(strFolderPath);
//獲取文件夾下所有的文件
foreach (FileInfo feInfo in dyInfo.GetFiles())
{
//判斷文件日期是否小於今天,是則刪除
if (feInfo.CreationTime < DateTime.Today)
feInfo.Delete();
}
