The look up table goes in months.bat:
:: one record per line
:: = is the delimiter
Given a month number, you can then look up the month abbreviation as follows:
:: Enable numeric comparison in if statements (Windows NT or better)
:: Set the month number you want to look up
:: 8 is August
:: Look up the months abbreviation (e.g. 8 is aug, 9 is sep, 10 is oct)
@FOR /F "tokens=1,2 delims==" %%i IN ('months.bat') DO @IF %%i EQU %MN% SET MW=%%j
:: The month abbreviation is now the %MW% variable
@ECHO The month abbreviation corresponding to %MN% is %MW%.
- ‘months.bat’ executes that file and pipes the output to the FOR /F command
- delims== sets the delimiter to the equals sign
- tokens=1,2 means you want the first two tokens (e.g. 1 and aug for 1=aug=August)
- %%i means the first token will go in %%i, second in %%j, etc
Alternate solutions are welcome. I’m still a bit unclear on the difference between %%i, %i, and %i%.