Windows Batch Script Get Current Drive name

前端 未结 8 1793
情话喂你
情话喂你 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:11

    %CD:~0,2%
    

    This will give you the current drive in the format C: , i.e. first 2 chars from the current working directory

    C:\Users\ashish>ECHO %CD:~0,2%
    C:
    
    D:\projects>ECHO %CD:~0,2%
    D:
    
    D:\projects>ECHO %CD%
    D:\projects
    

提交回复
热议问题