2011-06-25 205 views
2

考虑到参数是相对于当前目录的文件路径,我如何才能将参数设置为bat文件的目录?BAT文件:参数路径

比如我有以下文件:

C:\folder1\mybat.bat 
C:\folder2\x.jpg 

from C:\ I run: folder1\mybat.bat folder2\x.jpg 
Now I want to get: C:\folder2 because that's the folder of x.jpg 

from C:\folder1 I run: mybat.bat ..\folder2\x.jpg 
Result is the same as above 

from C:\folder2 I run: ..\folder1\mybat.bat x.jpg 
Result is again the same, the folder of x 
+0

你检查出[的Windows PowerShell(http://en.wikipedia.org/wiki/Windows_PowerShell)呢?它比批处理文件或命令提示符强大得多。 – TrueWill

回答

3

%~dp1应该给你你想要的东西。

其实你可以做help call并看到很多选择。的%~dp1描述 -

%〜DP1 - %1扩展到一个驱动器 号和路径