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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With