[ACCEPTED]-Batch : Checking the number of parameters-batch-file
Accepted answer
You can simply test for existence of a third 9 parameter and cancel if present:
if not "%~3"=="" (
echo No more than two arguments, please
goto :eof
)
But more 8 specifically, there is no direct way of 7 getting the number of arguments passed to 6 a batch, short of shift
ing and counting them. So 5 if you want to make sure that no more than 4 19 arguments are passed, then you need to 3 do exactly that. But if the number of expected 2 arguments is below 9 above method works 1 well.
IF NOT "%3"=="" GOTO Too_Many_Args
0
Here is my small example for gathering and 2 parsing a list of arguments and passing 1 to external command:
@echo off
setlocal enabledelayedexpansion
if %1. EQU . (
echo %~0 [-t NUM] FILE [FILE...]
goto end
)
:args_loop
if "%~1" EQU "-t" (
set arg_t=%1
set arg_t_val=%2
shift
) else (
set files=!files! %1
)
shift
if %1. NEQ . goto args_loop
:args_loop_end
x:\path\to\external.exe %arg_t% %arg_t_val% %files%
:end
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.