Archive

Posts Tagged ‘old’

Windows – Delete Old Files

October 8, 2008 scripthacks 1 comment

A few cautionary warnings… this script will delete files from whatever location you specify as LOGPATH.  Use with care. As a best practice I always create my logs with a pre-fix. ex: CheckUpTime-.log which can then be used in the deletion script. This will ensure that you only delete logs that start with “CheckUpTime”. 

:: Delete log files older then 14 days
set LOGPATH=C:Logs

:: Echo’s logs which will be deleted (use this before using the command which contains “del”)
forfiles -p %LOGPATH% -m CheckUpTime-*.* -d -14 -c “cmd /c echo 0×22@Path@File0×22″

:: Actual Delete Command (remove :: to run command)
::forfiles -p %LOGPATH% -m CheckUpTime-*.* -d -14 -c “cmd /c del /q @path”