cmd变量扩展
参考: https://stackoverflow.com/questions/17063947/get-current-batchfile-directory/17064031#17064031
ystem read-only variable %CD%
keeps the path of the caller of the batch, not the batch file location. 系统只读变量 %CD%
保存的是批处理调用者的路径,而不是批处理文件的位置。
You can get the name of the batch script itself as typed by the user with %0
(e.g. scripts\mybatch.bat
). Parameter extensions can be applied to this so %~dp0
will return the Drive and Path to the batch script (e.g. W:\scripts\
) and %~f0
will return the full pathname (e.g. W:\scripts\mybatch.cmd
). 您可以使用 %0
获取用户键入的批脚本名称(例如 scripts\mybatch.bat
)。(即可获取用户输入的批脚本名称(例如 scripts\mybatch.bat
)。可以对其进行参数扩展,因此 %~dp0
将返回批脚本的驱动器和路径(例如 W:\scripts\
),而 %~f0
将返回完整路径名(例如 W:\scripts\mybatch.cmd
)。
You can refer to other files in the same folder as the batch script by using this syntax: 使用此语法,您可以引用与批脚本位于同一文件夹中的其他文件:
CALL %0\..\SecondBatch.cmd
This can even be used in a subroutine, Echo %0
will give the call label but, echo "%~nx0"
will give you the filename of the batch script. 这甚至可以在子程序中使用, Echo %0
将给出调用标签,但 echo "%~nx0"
将给出批脚本的文件名。
When the %0
variable is expanded, the result is enclosed in quotation marks. 扩展 %0
变量时,结果用引号括起来。
发表回复