How to get the path of a batch script without the trailing backslash in a single command?

后端 未结 6 1121
闹比i
闹比i 2021-02-02 07:49

Suppose I wish to get the absolute path of a batch script from within the batch script itself, but without a trailing backslash. Normally, I do it this way:

SET          


        
6条回答
  •  清酒与你
    2021-02-02 08:23

    Example script "c:\Temp\test.cmd":

    @set BuildDir=%~dp0.
    @echo Build directory: "%BuildDir%"
    

    Run in console:

    d:\> cmd /C c:\Temp\test.cmd
    Build directory: "c:\Temp\."
    

提交回复
热议问题