Find USB Drive letter

前端 未结 5 453
星月不相逢
星月不相逢 2020-12-18 16:57

I need to get the drive letter of the usb pen drive.the command CHDIR >drive.txt gives me the drive letter L:.How do I read/get this info \"L:\" without quotes into a variab

5条回答
  •  半阙折子戏
    2020-12-18 17:29

    Since cd will output something like:

    c:\documents and settings\pax
    

    you need to just grab the first field using "\" as the delimiter as follows:

    for /f "delims=\" %d in ('cd') do set curdrv=%d
    

    This will set the environment variable curdrv to c: for the aforementioned output.

    Don't forget to use the double-% (%%d) variant if running inside a cmd file.

提交回复
热议问题