Windows Batch Script Get Current Drive name

前端 未结 8 1792
情话喂你
情话喂你 2021-02-02 09:30

I have a batch file which is on a usb key. I need to know the drive name the batch is in.

Example, if it\'s E:\\mybatch.bat it should find E:\\ same thing for F:\\, G:\\

8条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-02 10:10

    If run from inside a .CMD/.BAT file, you can use %~dp0 to get the current/working directory. This one is a little safer as it is aware of UNC paths and such. Reference for the syntax of that variable is available here.

提交回复
热议问题