%1、%2、…是一种可替换参数,也就是相当于是一个内存变量,%1就是命令后的第一个参数,%2是命令后的第二个参数。…%n就是第n个参数,它可以用实际参数来替换这些可变参数,比如DIR /W /P,则%1=W ,%2=P,而且它还可以传递到子批处理程序。这在批处理文件里特别有用,例如你建立一个A.BAT,内容为:CALL DIR %1 %2,则你执行A /W /P 即相当于执行DIR /W /P。或者你建一个B.BAT,内容为:
IF %1=D GOTO 1
GOTO END
:1
DIR
:END
则你执行B /D,则执行DIR命令。
%1, %2, ... are replaceable parameters, which are equivalent to memory variables. %1 is the first parameter after the command, %2 is the second parameter after the command. ... %n is the nth parameter. It can be replaced with actual parameters. For example, DIR /W /P, then %1 = W, %2 = P, and it can also be passed to a sub-batch program. This is particularly useful in batch files. For example, you create an A.BAT with the content: CALL DIR %1 %2, then you execute A /W /P which is equivalent to executing DIR /W /P. Or you create a B.BAT with the content:
IF %1=D GOTO 1
GOTO END
:1
DIR
:END
Then you execute B /D, which executes the DIR command.