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

后端 未结 7 1995

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 02:39

    Great example from Strawberry Perl's portable shell launcher:

    set drive=%~dp0
    set drivep=%drive%
    if #%drive:~-1%# == #\# set drivep=%drive:~0,-1%
    
    set PATH=%drivep%\perl\site\bin;%drivep%\perl\bin;%drivep%\c\bin;%PATH%
    

    not sure what the negative 1's doing there myself, but it works a treat!

提交回复
热议问题