批处理中%~1和%1有什么区别?

9
在批处理中,我有时看到用于开关的%~1%1。它们有什么区别?它们似乎都对我有效。
例如:
if "%~1"=="" echo No variable specified.

并且

if "%1"=="" echo No variable specified.

似乎可以互换使用。
1个回答

15

解释在 For /?call /? 中都有,会扩展 %1 并删除任何周围的引号 (")

    %~1         - expands %1 removing any surrounding quotes (")
    %~f1        - expands %1 to a fully qualified path name
    %~d1        - expands %1 to a drive letter only
    %~p1        - expands %1 to a path only
    %~n1        - expands %1 to a file name only
    %~x1        - expands %1 to a file extension only
    %~s1        - expanded path contains short names only
    %~a1        - expands %1 to file attributes
    %~t1        - expands %1 to date/time of file
    %~z1        - expands %1 to size of file
    %~$PATH:1   - searches the directories listed in the PATH
                   environment variable and expands %1 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

您可能会发现这个链接很有趣 运行.bat文件的命令


谢谢!非常感谢。 - ditheredtransparency

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接