Friday, May 23, 2014

How to Obtain USB Removable Disk Drive Letter Automatically with a Batch Script

Purpose of this script is to determine the drive letter of a USB thumb drive.  Depending on the hardware and drive partitions, every computer you plug a thumb drive into is different.  This will give you the drive letter assuming it is the only removable disk.

for /F "tokens=2 delims==" %%i in ('wmic logicaldisk where "drivetype=2" get name /format:value') do (

    set "usb=%%i"
    call :BREAK
)

:BREAK
echo Your USB Drive is %usb%


NOTE:  The "do" must be on the same line.

Source:  Link Link

No comments:

Post a Comment

ShareThis