Using Robocopy, you can delete log files from applications that are not particularly good at tidying up after themselves. I recently ran into an application that was logging everything and not keeping the log duration under control. There are a wealth of options to be able to manage this, but I wanted a simple and reliable solution.
Robocopy is a very versatile utility and as you can see from my earlier post on Backing UP IIS, it’s something I like to make use of. Applications that use log files are not always good at managing them, often relying on manual intervention to keep the number of files manageable and the file sizes small.
The principle here is that you use Robocopy to move all files older than a certain number of days to a different folder and then delete them.
It’s simple, it only needs Robocopy and the built in RMDIR command.
[code]
@echo off
robocopy c:\application\logs c:\temp\delete /e /MOVE /MINAGE:90
rmdir c:\temp\delete /s /q
[/code]
The Robocopy command moves any files in the c:\application\logs folder that are older than 90 days (/MINAGE:90) into c:\temp\delete
The RMDIR command then deletes c:\temp\delete without prompting.
Once you’ve got the script running, it’s then time to ensure it runs routinely. The simplest way to do this is to use the in built Windows Task Scheduler. For me, running the job weekly was enough.
I’m sure there are a million ways to do this, perhaps some without even using an additional utility like Robocopy but this has been working without issue for me.