The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,533 other followers

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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: