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

前端 未结 8 1312

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

提交回复
热议问题