What does %~dp0 mean, and how does it work?

后端 未结 7 2098

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

But the label itself seems very cryptic to me... What is the ~<

7条回答
  •  执念已碎
    2020-11-22 03:03

    An example would be nice - here's a trivial one

    for %I in (*.*) do @echo %~xI
    

    it lists only the EXTENSIONS of each file in current folder

    for more useful variable combinations (also listed in previous response) from the CMD prompt execute: HELP FOR which contains this snippet

    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
    

提交回复
热议问题