Published
- 1 min read
c# delete files older than x months
The solution for this is noted below
c# delete files older than x months
Solution
using System.IO;
string[] files = Directory.GetFiles(dirName);
foreach (string file in files)
{
FileInfo fi = new FileInfo(file);
if (fi.LastAccessTime < DateTime.Now.AddMonths(-3))
fi.Delete();
}
Try other methods by searching on the site. That is if this doesn’t work