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

后端 未结 7 2000

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:56

    Another tip that would help a lot is that to set the current directory to a different drive one would have to use %~d0 first, then cd %~dp0. This will change the directory to the batch file's drive, then change to its folder.

    Alternatively, for #oneLinerLovers, as @Omni pointed out in the comments cd /d %~dp0 will change both the drive and directory :)

    Hope this helps someone.

提交回复
热议问题