Image

Image

Search This Blog

Thursday, September 01, 2016

CMD tmpwatch / logwatch

@echo off
:: (c)2015 s@toXX.guru

set watchdir="C:\Program Files\Research In Motion\BlackBerry Enterprise Server\logs"

:: remove older files
forfiles /p %watchdir% /s /m *.* /c "cmd /c Del @path" /d -30
:: remove empty folders !!! cd on a different drive first, if that's the case !!!
:: D:\
cd  %watchdir%
for /f "tokens=*" %d in ('dir /ad/b/s ^| sort /R') do rd "%d"

Shorter version:
forfiles /p [PATH] /s /m [FILE-PATTERN] /D -[MM/DD/yyyy] /c "cmd /c del @path"
for /f "delims=" %%d in ('dir [PATH] /s /b /ad ^| sort /r') do rd "%%d"

Blog Archive