0

This is sort of silly, but today is the first day I'm using batch scripts, so bear with me. I'm using the following code to find a particular drive letter assigned to a volume.

set "volume=\Volume{8bc9f784-9f15-11e4-be58-a60f30d14122}"
set "drive="

for  %%D in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
mountvol %%D: /L | findstr "%volume%" >nul
if not errorlevel 1 set "drive=%%D"
)

Now I need to do the opposite. I need to save the volume id from a particular drive letter. I can easily do that using Mountvol X: /l, where X is the drive letter. But how do I assign the output of that command to a variable in batch scripting?

0

1 Answer 1

0
for /f %%a in ('mountvol X: /l') do set volname=%%a
echo %volname%
2
  • Thank you. I'm using it with tokens and delims, although it isn't necessary, I guess. May 8, 2015 at 20:43
  • Not in this case because it's a single unbroken string with no spaces, but otherwise yes you'd need those.
    – Karan
    May 8, 2015 at 20:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .