Query to search the older files in a folder and delete them using LINQ

Posted by Prabhukiran345 under LINQ category on | Points: 40 | Views : 1007
var query = from o in Directory.GetFiles("/YourFolder", "*.*",
let x = new FileInfo(o)
where x.CreationTime <= DateTime.Now.AddMonths(-6)
select o;
foreach (var item in query)

This will delete all files older than 6 month from current datye from the Specified folder.

Comments or Responses

Login to post response