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"))