I have a PC in which I insert a USB Drive and execute a batch script, but the USB Drive interacts with the computer, so I need to know in which Drive Letter it is mounted.
I tried this
for /f "tokens=2,3 delims= " %%A in ('WMIC logicaldisk where "DriveType=2" get /value | find "Caption="') do (
set drive=%%A
)
But I get an error stating Did not expect %%A at this moment
.
I know this works
@echo off
for /F "usebackq tokens=1,2,3,4 " %%i in (`wmic logicaldisk get caption^,description^,drivetype
2^>NUL`) do (
if %%l equ 2 (
echo %%i is a USB drive.
)
)
But it implies having to save it in a .bat file, and I don't want to do that.
Ideally, what I want to do is to be able to switch to the USB Drive without needing to launch it from a .bat
file, so this command should allow me to get the Drive Letter. Afterwards, the script continues.