日期:2014-05-17 浏览次数:21024 次
//检查文件备份目录,删除过期文件
double SaveDay = Convert.ToDouble(Utils.SaveTime);
DateTime dtNow = DateTime.Now;
foreach (string dir in Directory.GetDirectories(Utils.CurrentPath + "\\发送备份目录"))
{
DirectoryInfo bf = new DirectoryInfo(dir);
DateTime dtCreat = bf.CreationTime;
TimeSpan ts = dtNow.Subtract(dtCreat);
[color=#FF0000]foreach (string f in dir)
{
File.SetAttributes(f, System.IO.FileAttributes.Normal);//这句是为了防止备份目录中有只读文件时删不掉,所以提前把文件的属性设为normal
}[/color]
if (ts.TotalDays > SaveDay)
{
bf.Delete(true);
}
}
File.SetAttributes(dir, System.IO.FileAttributes.Normal);
------解决方案--------------------