@echo off setlocal for /f "tokens=1-3 delims=/ " %%a in ('date /t') do (set currday=%%a) && (set currmonth=%%b) && (set curryear=%%c) ::move the files from /BACKUP/ to a storage folder. ::format: [year]-[month]_Week_[week of month] set /a currweek=(%currday%/7)+1 set currdate=%curryear%-%currmonth%_Week_%currweek% md D:\BACKUP\%currdate% move D:\BACKUP\*.tar.gz D:\BACKUP\%currdate% ::remove the 3 month old folder set /a oldmonth=%currmonth%-3 if %oldmonth% LSS 0 set oldmonth=%oldmonth%+3 if %oldmonth% LSS 10 set oldmonth=0%oldmonth% echo D:\BACKUP\%curryear%-%oldmonth%_Week_%currweek% endlocal