Get last command line argument in windows batch file – via: Stack Overflow
Posted by jpluimers on 2011/12/29
Sometimes you want to parse commandline arguments in batch files starting at the last one.
For parsing them left to right, the shift command comes in handy.
But there is no “shift-reverse” command, so you need some trick.
StackOverflow to the rescue: user Joey provides this really nice answer:
The easiest and perhaps most reliable way would be to just use cmds own parsing for arguments and shift then until no more are there.Since this destroys the use of %1, etc. you can do it in a subroutine
@echo off
call :lastarg %*
echo Last argument: %LAST_ARG%
goto :eof
:lastarg
set "LAST_ARG=%~1"
shift if not "%~1"=="" goto :lastarg
goto :eof
:eof
–jeroen
via: Get last command line argument in windows batch file – Stack Overflow.






Leave a comment