Alex Rivera | Logout

Delete files older than 3 months old in a directory using .NET

Asked 2010-02-08T14:49:57.633
158

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 am looking for files that are older than 90 days, in other words files created less than 90 days ago should be kept, all others deleted.

Edit
Report

1 Answer

1

Basically you can use Directory.Getfiles(Path) to get a list of all the files. After that you loop through the list and call GetLastAccessTim() as Keith suggested.

answered 2010-02-08T14:55:22.313

Your Answer