windows - 找出正在运行的批处理文件的文件名

标签 windows batch-file

在 Windows 批处理文件中,我想弄清楚这个批处理文件的完全限定路径名是什么。

我试过 %0 但这只给了我键入的命令(例如,只有没有路径或扩展名的文件名)。

最佳答案

供您引用,

你需要启用command extends,Win 2000之前是不存在的(我不知道NT4)

查看:cmd.exe/?

/E:ON   Enable command extensions (see below)
/E:OFF  Disable command extensions (see below)

Windows 默认启用命令扩展。

我建议阅读的另一个帮助是 FOR 命令。 它包含这些标志的完整含义。

查看:for/? 来自 cmd

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

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.

关于windows - 找出正在运行的批处理文件的文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/343518/

相关文章:

c++ - 我可以一次将整个 NTFS 目录树读入 RAM 吗?

windows - 使用自定义名称安装 Windows 服务

windows - Windows 7 上的核素包

java - 如何动态命名批处理文件中一行java代码的输出

windows - 批处理命令如何为 set/p 制作列表

batch-file - 防止 "abort"在 Windows 批处理中进行 npm 安装

windows - 通过变量执行cmdlet?

python - pyodbc 在我的机器上很慢,但在其他机器上不是

date - Bat 文件在复制到另一台电脑时在我的电脑上工作。语法错误

batch-file - 批处理文件 - 在 for 循环中更改变量值