Search

July 16, 2012

Deleting old files on Windows

I ran into a situation today where I wanted to script deletion of folders older than a set number days on an old Windows 2000 machine. (The culprit is a commercial SMTP spam and virus filter that does not clean up after itself when it updates. Eventually the drive gets full and no mail comes through.) I found a solution using forfiles but this version of Windows does not have it. I found myself searching the web and gnashing my teeth over the limitations of Windows batch scripting.

That is when I remembered that Windows batch processing can be quite robust if you use the right tools. Namely, you can write JScript (i.e. JavaScript) and Visual Basic scripts for Windows that utilize ActiveX to make use the of whole Windows API. A little googling later and I had the following script: