问题描述
|
考虑到参数是相对于当前目录的文件路径,如何将参数的目录设置为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
解决方法
%~dp1
应该给您您想要的。
实际上,您可以做help call
,并且可以看到很多选择。 %~dp1
-
%〜dp1-将%1扩展到驱动器
仅字母和路径