useage: Get_MonthList.bat %Num%
The %Num% defines how many months need to list

See code:
@echo off & setlocal enabledelayedexpansion
set num=%1
call :Get_MonthList %date:~0,4%%date:~5,2% %Num%
goto :eof
:Get_MonthList
set Month0=%1
set /p = !Month0! <nul
for /l %%i in (1,1,%2) do (
set /a Month%%i=!Month0!-1
if "!Month%%i:~4,2!"=="00" (
rem when 201806 decreasing by 1 to be 201800, then 2018 need to -1 and 00 need to be 12
set /a Month_1_4=!Month0:~0,4!-1
set Month%%i=!Month_1_4!12
)
rem re-declear Month0
set Month0=!Month%%i!
rem Output the result in one line
set /p =!Month%%i! <NUL
rem echo Debug:Month0:!Month0!
rem pause>nul
)
goto :eof
本文介绍了一个使用批处理脚本生成指定数量月份列表的方法。该脚本通过参数定义需要列出的月份数,并能够正确处理跨年份的情况。文章详细展示了如何递归地减少月份并调整年份以保持正确的月份顺序。

被折叠的 条评论
为什么被折叠?



