In my situation, we got a lot of proof of delivery need to be cleaned up regularly. The service requirement is we keep these files up to 1 year.


The script is:

@echo off
rem get the date tokens
for /f "tokens=1-4 delims=/ " %%i in ("%date%") do (
 set dow=%%i
 set month=%%k
 set day=%%j
 set year=%%l

rem The month, day and year variables are numbers, but in my example, the month folder are in letter format like Jan, Feb, so need to mapping the words to the numbers
rem to letters.
set N=%month%
 :: Call and mask out invalid call targets
 goto :%N% 2>nul || (
 :: Default case
 echo "could not find the month folder"
 goto :switch-case-end
 set mon=Jan
 goto :switch-case-end 
 set mon=Feb
 goto :switch-case-end
 set mon=Mar
 goto :switch-case-end 
 set mon=Apr
 goto :switch-case-end
 set mon=May
 goto :switch-case-end
 set mon=Jun
 goto :switch-case-end 
 set mon=Jul
 goto :switch-case-end
 set mon=Aug
 goto :switch-case-end
 set mon=Sep
 goto :switch-case-end
 set mon=Oct
 goto :switch-case-end 
 set mon=Nov
 goto :switch-case-end
 set mon=Dec
 goto :switch-case-end

set /a year -= 1
set @bslpod=P:\%year%\%mon%\%day%%month%%year%
set @bslCOLESDM=P:\%year%\%mon%\COLESDM\%day%%month%%year%
set @bslSOG=P:\%year%\%mon%\SOG\%year%%month%%day%
Set @tfs=P:\Tasfreight\%year%\%mon%\%year%%month%%day%
Set @tfssog=P:\Tasfreight\%year%\%mon%\SOG\%year%%month%%day%
echo %@bslpod%
rmdir %@bslpod% /Q /S
rmdir %@bslCOLESDM% /Q /S
rmdir %@bslSOG% /Q /S
rmdir %@tfs% /Q /S
rmdir %@tfssog% /Q /S