::Get Today's Date
:: Set the compair date to the Julian of today's date.
Call :jdate %Year% %Month% %Day%
Set /a CompairDate=%jdate%
:: Set the compair date minus the number of days.
Set /a CompairDate=!CompairDate!-1
for /f "tokens=*" %%a in ('dir c:\test\ /b /s /ad') do (
set /a FileDate=%%a:~-16,8%
::Convert Filedate into a Julian Date
call :jdate !FileYear! !FileMonth! !FileDay!
set /a FileDate=!Jdate!
if "!FileDate!" lss "!CompairDate!" (
del "%%a" /s /q
echo *Deleted* %%a
:: Convert date to Julian
IF %MM:~0,1% EQU 0 SET MM=%MM:~1%
IF %DD:~0,1% EQU 0 SET DD=%DD:~1%
SET /A Month1 = ( %MM% - 14 ) / 12
SET /A Year1 = %1 + 4800
SET /A JDate = 1461 * ( %Year1% + %Month1% ) / 4 + 367 * ( %MM% - 2 -12 * %Month1% ) / 12 - ( 3 * ( ( %Year1% + %Month1% + 100 ) / 100 ) ) / 4 + %DD% - 32075
You have to convert the dates to Julian dates first because if Today's date was 01/01/2011 and you just subtracted 1 from it then the date would be 00/01/2011. Julian dates allow you to subtract 1 and still get the result you wanted which would have been 12/31/2010.
The above code is untested so you may want to remove the DEL command until you see how it works.
P.S. I would just use RAZOR's code because the NOW command is already converted to a Julian Date. The only problem with RAZOR's code is that it look at the creation date of the folder and not the name of the folder.