Batch - %~dp0 vs %cd%

总结

%~dp0 只表示将要“运行的”bat命令的folder,不包含bat自己的名称。

%cd%表示,“运行处”的folder 。

 

示例脚本内容

cd-dp0.bat存放在f盘

@echo off
echo this is %%cd%% : %cd%
echo this is %%~dp0 : %~dp0

  

在C:\Users\Administrator执行脚本

执行:

C:\Users\Administrator>f:\cd-dp0.bat

结果:

this is %cd% : C:\Users\Administrator
this is %~dp0 : f:\

  

在F:\执行脚本

执行:

F:\>cd-dp0.bat

结果:

this is %cd% : F:\
this is %~dp0 : F:\

  

 

posted on 2019-10-11 17:41  frank_cui  阅读(300)  评论(0)    收藏  举报

导航

levels of contents