:DeleteIfOld name days tnow -- deletes file or directory if older than given number of days :: -- name [in] - name of file or directory :: -- days [in] - number of days to expire :: -- tnow [in] - today's date in julia days SETLOCAL set "days=%~2" set "tnow=%~3" call:ftime tfile "%~1" set /a "diff=tnow-tfile" if %diff% LEQ %days% EXIT /b set "attr=%~a1" rem ECHO.%attr%, %attr:~0,1%, %~nx1 is %diff% days old if /i "%attr:~0,1%"=="d" ( rd /Q /S "%~1" ) ELSE ( del /Q "%~1" ) EXIT /b