Batch interpreter parses command line in slightly different manner than pure command line parser (read answers to another question at StackOverflowanswers to another question at StackOverflow):
- command line: to avoid expanding
%MYAPPSDIR%
by command line interpreter, the%
percent character should be escaped by the standard CLI escape character (^
caret):^%MYAPPSDIR^%
or^%1
; .bat
script: to avoid expanding%MYAPPSDIR%
or%1
by batch interpreter, the%
percent character should be doubled as follows:%%MYAPPSDIR%%
and%%1
, respectively.
To distinguish parameters supplied to your batch script:
set "par1=%~1"
if "%par1%"=="" (
echo no parameter supplied
goto :eof
) else (
set "par=%par1:.exe=%"
)
if "%par%"=="%par1%" (
echo .exe not present
) else (
echo .exe present
)
or (maybe better)
set "par1=%~1"
if "%par1%"=="" (
echo no parameter supplied
goto :eof
) else (
set "par=%par1:~-4%"
)
if /I "%par%"==".exe" (
echo .exe present
) else (
echo .exe not present
)
or (maybe the best)
set "par1=%~1"
if "%par1%"=="" (
echo no parameter supplied
goto :eof
) else (
set "par=%~x1"
)
if /I "%par%"==".exe" (
echo .exe present
) else (
echo .exe not present
)
Resources (required reading):
- (command reference) An A-Z Index of the Windows CMD command line
- (additional particularities) Windows CMD Shell Command Line Syntax
- (
%~1
etc. special page) Command Line arguments (Parameters) - (
%par1:~-4%
substring) Variables: extract part of a variable - (
%par1:.exe=%
) Variable Edit/Replace