/ Published in: C#
From Digital Colony, nice little function that will delete files older than given time frame. Example is 3 minutes. Commented out is a sample of files older than 1 day.
- protected void CleanImageFolder()
- string imgFolder = Server.MapPath("~/lab/maskemail/img/");
- string imgList = Directory.GetFiles(imgFolder, "*.jpg");
- foreach (string img in imgList)
- FileInfo imgInfo = new FileInfo(img);
- if (imgInfo.LastWriteTime < DateTime.Now.AddMinutes(-3))
- //if (imgInfo.LastWriteTime < DateTime.Now.AddDays(-1))
You need to login to post a comment.