Type something to search...

Delete Old Files

I was just trying to get some backups configured and I wanted a way of deleting files from a directory stucture that were older than a certain date. I couldn’t figure out how to do it easier from a Windows 2003 command script, so I wrote a quick C# console app to do the job. I’ve included the code and a copy in case you find this useful. WARNING: Use this at your own risk, as I wrote this for myself I haven’t spent any time putting in “Are You Sure” prompts or anything. If you were to do something crazy like DeleteOldFiles 5 c:\ it will delete any file on your C:\ drive that has not been written to in 5 days - including things in the Windows directory..

Update: The second I posted this, I noticed the ForFiles command in the Windows Server 2003 resource kit that works a bit like find on unix. Hey ho, at least I wrote some C# code today.