title: windows cmd get USB drive letter automatically without batch file
body: <p>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.</p>
  
  <p>I tried this </p>
  
  <pre><code>    for /f "tokens=2,3 delims= " %%A in ('WMIC logicaldisk where "DriveType=2" get /value | find "Caption="') do (
  set drive=%%A
  )
  </code></pre>
  
  <p>But I get an error stating <code>Did not expect %%A at this moment</code>.</p>
  
  <p>I know <a href="https://stackoverflow.com/a/20155650/7547440">this</a> works</p>
  
  <pre><code>@echo off
  
  for /F "usebackq tokens=1,2,3,4 " %%i in (`wmic logicaldisk get caption^,description^,drivetype 
  
  2^&gt;NUL`) do (
  
  if %%l equ 2 (
  echo %%i is a USB drive.
  )
  )
  </code></pre>
  
  <p>But it implies having to save it in a .bat file, and I don't want to do that.</p>
  
  <p>Ideally, what I want to do is to be able to switch to the USB Drive without needing to launch it from a <code>.bat</code> file, so this command should allow me to get the Drive Letter. Afterwards, the script continues.</p>