I would like to know (using C#) how I can delete files in a certain directory older than 3 months, but I guess the date period could be flexible.
Just to be clear:
i have try this code and it works very well, hope this answered
namespace EraseJunkFiles
{
class Program
{
static void Main(string[] args)
{
DirectoryInfo yourRootDir = new DirectoryInfo(@"C:\yourdirectory\");
foreach (FileInfo file in yourRootDir.GetFiles())
if (file.LastWriteTime < DateTime.Now.AddDays(-90))
file.Delete();
}
}
}