Delete All PDF files (*.pdf) from a folder older than one day

Posted by kgovindarao523-21772 under C# category on | Points: 40 | Views : 789
I want to delete all pdf files were created longer than one day.
Here is the code.
string[] files = Directory.GetFiles(strFolderPath);//Folder path ex: .GetFiles(@"C:\Test")
foreach (string file in files)
FileInfo fi = new FileInfo(file);
//you can change the condition based on your requirement for ex.for 5 days or only .docx files
if (fi.CreationTime.Date < DateTime.Now.AddDays(-1) && fi.FullName.Contains(".pdf"))

Comments or Responses

Login to post response