指定批处理文件中需要绝对值的相对路径

时间:2013-12-28 16:23:32

标签: windows batch-file relative-path absolute-path

我有以下批处理文件:

"C:\TapTest\PsExec.exe" /accepteula -i -s "C:\TapTest\tapinstall.exe" 
    ->  install "C:\TapTest\driver\OemWin2k.inf" tap0901

批处理文件的位置是:

c:\TapTest\TapInstall.bat

我希望能够执行以下操作(使用相对路径):

"PsExec.exe" /accepteula -i -s "tapinstall.exe" install "driver\OemWin2k.inf" tap0901

但是tapinstall.exe需要一个绝对路径作为参数。如何在没有硬编码的情况下获取批处理文件以提供绝对路径?

1 个答案:

答案 0 :(得分:2)

"PsExec.exe" /accepteula -i -s "%~dp0tapinstall.exe" install "%~dp0driver\OemWin2k.inf" tap0901

%0 =对当前批处理文件的引用

%~dp0 =批处理文件所在的驱动器和路径