是什么%〜DP0的意思,它是如何工作的? [英] What does %~dp0 mean, and how does it work?

查看:118
本文介绍了是什么%〜DP0的意思,它是如何工作的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我觉得%〜DP0 非常有用,我用了很多,使我的批处理文件,更便于携带。

I find %~dp0 very useful, and I use it a lot to make my batch files more portable.

但标签本身似乎很神秘,我...什么是在做什么?确实 DP 的意思是驱动器和路径?确实在 0 参考%0 的路径包括文件名的批处理文件?

But the label itself seems very cryptic to me... what is the ~ doing? does dp mean drive and path? does the 0 refer to %0, the path to the batch file that includes the file name?

还是只是一个奇怪的标签?

Or is it just a weird label?

我也想知道,如果它是一个记录的功能,或者说容易被德precated。

I'd also like to know if it is a documented feature, or something prone to be deprecated.

推荐答案

调用

for /?

在命令行提供了有关这个语法帮助(这可以为外部使用,也这只是帮助的地方可以找到的地方)。

in the command-line gives help about this syntax (which can be used outside FOR, too, this is just the place where help can be found).

在另外,对于取代
  变量引用已得到增强。
  您现在可以使用下列可选
  语法:

In addition, substitution of FOR variable references has been enhanced. You can now use the following optional syntax:

%~I         - expands %I removing any surrounding quotes (")
%~fI        - expands %I to a fully qualified path name
%~dI        - expands %I to a drive letter only
%~pI        - expands %I to a path only
%~nI        - expands %I to a file name only
%~xI        - expands %I to a file extension only
%~sI        - expanded path contains short names only
%~aI        - expands %I to file attributes of file
%~tI        - expands %I to date/time of file
%~zI        - expands %I to size of file
%~$PATH:I   - searches the directories listed in the PATH
               environment variable and expands %I to the
               fully qualified name of the first one found.
               If the environment variable name is not
               defined or the file is not found by the
               search, then this modifier expands to the
               empty string


  
  

的改性剂可被组合以得到
  多重结果:

The modifiers can be combined to get compound results:

%~dpI       - expands %I to a drive letter and path only
%~nxI       - expands %I to a file name and extension only
%~fsI       - expands %I to a full path name with short names only
%~dp$PATH:I - searches the directories listed in the PATH
               environment variable for %I and expands to the
               drive letter and path of the first one found.
%~ftzaI     - expands %I to a DIR like output line

在上面的例子中,%I和路径可以
  其他有效数值替换。
  %〜语法被一个有效终止
  变量名。采摘大写
  类似%I的变量名使它更
  易读,而且避免与困惑
  改性剂,这是不区分
  敏感。

In the above examples %I and PATH can be replaced by other valid values. The %~ syntax is terminated by a valid FOR variable name. Picking upper case variable names like %I makes it more readable and avoids confusion with the modifiers, which are not case sensitive.

有不同的字母,你可以像使用˚F为全路径名 D 的驱动器盘符, p 的路径,也可以组合使用。 %〜是为每个序列和号码的开头 I 表示它适用于参数%I (其中 0%是批处理文件的完整名称,就像你假设)。

There are different letters you can use like f for "full path name", d for drive letter, p for path, and they can be combined. %~ is the beginning for each of those sequences and a number I denotes it works on the parameter %I (where %0 is the complete name of the batch file, just like you assumed).

这篇关于是什么%〜DP0的意思,它是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆