I want to write some code that deletes all DIRECTORIES older than 7 days.
So:
- Check directory :
D:\this
- If folder older than 7 days -> delete it from the system.
I want to write some code that deletes all DIRECTORIES older than 7 days.
So:
D:\this
You can lookup using the DirectoryInfo util
DirectoryInfo d = new DirectoryInfo(dir);
if (d.CreationTime < DateTime.Now.AddDays(-7))
d.Delete();
You can use DirectoryInfo
http://msdn.microsoft.com/en-us/library/system.io.directoryinfo.aspx
The voice of experience says to include sanity checks in your code that the directories you are deleting are in fact ones that you want to be deleting...