How to get the path of the batch script in Windows?

前端 未结 8 1314

I know that %0 contains the full path of the batch script, e.g. c:\\path\\to\\my\\file\\abc.bat

I would path to be equal to

相关标签:
8条回答
  • 2020-12-04 05:27

    That would be the %CD% variable.

    @echo off
    echo %CD%
    

    %CD% returns the current directory the batch script is in.

    0 讨论(0)
  • 2020-12-04 05:29

    You can use %~dp0, d means the drive only, p means the path only, 0 is the argument for the full filename of the batch file.

    For example if the file path was C:\Users\Oliver\Desktop\example.bat then the argument would equal C:\Users\Oliver\Desktop\, also you can use the command set cpath=%~dp0 && set cpath=%cpath:~0,-1% and use the %cpath% variable to remove the trailing slash.

    0 讨论(0)
提交回复
热议问题