%~d0 在 Windows 批处理文件中是什么意思? [英] What does %~d0 mean in a Windows batch file?

查看:28
本文介绍了%~d0 在 Windows 批处理文件中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看定义以下变量的批处理文件:

I'm looking at a batch file which defines the following variables:

set _SCRIPT_DRIVE=%~d0
set _SCRIPT_PATH=%~p0

  • %~d0%~p0 到底是什么意思?
  • 是否有一组众所周知的值,例如当前目录、驱动器、脚本参数?
  • 还有其他类似的快捷方式我可以使用吗?
    • What do %~d0 or %~p0 actually mean?
    • Is there a set of well-known values for things like current directory, drive, parameters to a script?
    • Are there any other similar shortcuts I could use?
    • 推荐答案

      魔法变量 %n 包含用于调用文件的参数:%0 是 bat 文件本身的路径,%1 是后面的第一个参数,%2 是第二个,依此类推.

      The magic variables %n contains the arguments used to invoke the file: %0 is the path to the bat-file itself, %1 is the first argument after, %2 is the second and so on.

      因为参数通常是文件路径,所以有一些额外的语法来提取路径的一部分.~d 是驱动器,~p 是路径(不带驱动器),~n 是文件名.它们可以组合,所以 ~dp 是驱动器+路径.

      Since the arguments are often file paths, there is some additional syntax to extract parts of the path. ~d is drive, ~p is the path (without drive), ~n is the file name. They can be combined so ~dp is drive+path.

      %~dp0 因此在 bat 中非常有用:它是执行 bat 文件所在的文件夹.

      %~dp0 is therefore pretty useful in a bat: it is the folder in which the executing bat file resides.

      您还可以获取有关文件的其他类型的元信息:~t 是时间戳,~z 是大小.

      You can also get other kinds of meta info about the file: ~t is the timestamp, ~z is the size.

      此处查看所有命令行命令的参考.for 下描述了波浪号魔术代码.

      Look here for a reference for all command line commands. The tilde-magic codes are described under for.

      这篇关于%~d0 在 Windows 批处理文件中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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