更新时间:2023-10-27 17:06:58
下一个脚本需要另一个参数顺序(批下来的名字,结束所有其它参数列表):
Next script requires another parameter order (list of batch names down to end all other parameters):
@ECHO OFF
SETLOCAL EnableExtensions
rem usage: 33955749.bat name address "first script", second, third
:loop
if "%~3" == "" goto :next
if exist "%~n3.bat" (
call "%~n3.bat" %1 %2
) else (
echo can't found file; failed call "%~n3.bat" %1 %2
)
shift /3
goto :loop
:next
有关调试目的,prepare样本文件第一script.bat
和 second.bat
;确保 third.bat
不存在:
For debugging purposes, prepare sample files "first script.bat"
and second.bat
; ensure that third.bat
does not exist:
==> >"first script.bat" echo @echo %~nx0 parameters: %%*=%*
==> >second.bat echo @echo %~nx0 parameters: %%*=%*
==> 2>NUL del third.bat
输出(表明上使用分隔符的独立性):
Output (shows independency on used delimiters):
==> 33955749 name address "first script", second, third
first script.bat parameters: %*=name address
second.bat parameters: %*=name address
can't found file; failed call "third.bat" name address
==> 33955749 name address "first script" second; third
first script.bat parameters: %*=name address
second.bat parameters: %*=name address
can't found file; failed call "third.bat" name address
另一种方法:拳头参数=一对双引号包围逗号分隔的一批名单:
Another approach: fist parameter = list of comma-separated batch names surrounded with a pair of double quotes:
@ECHO OFF
SETLOCAL EnableExtensions
rem usage: 33955749b "first script,second,third" name address
rem no spaces surrounding commas or names
rem wrong: 33955749b " first script , second, third" would fail
set "_names=%~1"
set "_names=%_names:,=","%"
rem debug echo _names="%_names%"
for %%G in ("%_names%") do (
if exist "%%~dpnG.bat" (
call "%%~dpnG.bat" %2 %3
) else (
echo can't found script; failed call "%%~dpnG.bat" %2 %3
)
)
输出(显示响应所用的分隔符):
Output (shows responsivity to used delimiters):
==> 33955749b "first script,second,third" name address
first script.bat parameters: %*=name address
second.bat parameters: %*=name address
can't found script; failed call "D:\bat\SO\third.bat" name address
==> 33955749b "first script, second,third" name address
first script.bat parameters: %*=name address
can't found script; failed call "D:\bat\SO\ second.bat" name address
can't found script; failed call "D:\bat\SO\third.bat" name address
请注意,这两个 33955749.bat
和 33955749b.bat
脚本
的.bat
。.bat
.例如, 33955749名称地址first.cmd second.cmd
将试图调用 first.bat
和 second.bat
。
资源(必读书,不完全):
Resources (required reading, incomplete):
%〜摹
,%〜1
等特殊页)的命令行参数(参数) %变量:StrToFind =%中newstr
等)的变量编辑/替换 %~G
, %~1
etc. special page) Command Line arguments (Parameters)%variable:StrToFind=NewStr%
etc.) Variable Edit/Replace