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% :switch-case-example :: Call and mask out invalid call targets goto :%N% 2>nul || ( :: Default case echo "could not find the month folder" ) goto :switch-case-end :01 set mon=Jan goto :switch-case-end :02 set mon=Feb goto :switch-case-end :03 set mon=Mar goto :switch-case-end :04 set mon=Apr goto :switch-case-end :05 set mon=May goto :switch-case-end :06 set mon=Jun goto :switch-case-end :07 set mon=Jul goto :switch-case-end :08 set mon=Aug goto :switch-case-end :09 set mon=Sep goto :switch-case-end :10 set mon=Oct goto :switch-case-end :11 set mon=Nov goto :switch-case-end :12 set mon=Dec goto :switch-case-end :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 :END