0

I do not have much experience with batch an d need a help with batch script. Task is, return drive letter as parameter to %disk_letter%

Idea is use this for search:

WMIC LogicalDisk Where VolumeName='MY_USB' Get /Format:list | FIND "Caption="

I have "Caption=G:" as the result. I need that %disk_leter% parameter was equal just "G:" Need help to finish this script.

Thank you!

user1615760
  • 1
  • 1
  • 2

2 Answers2

1

On Linux right now but here's what I think you'll need to do. Part 1: save the result of your FIND command to a variable, and 2: take a substring of the variable. The second part is simple, so I'll start with that (assuming that in the first step you named your variable var

@echo %var:~-2%

That's about as far as I'm comfortable in batch, so this next bit is cobbled together:

To store the result of your find as a variable, try amending your code to:

set cmd="WMIC LogicalDisk Where VolumeName='MY_USB' Get /Format:list | FIND "Caption=" "

FOR /F %%i IN (' %cmd% ') DO SET var=%%i

and then (remember above) output it with:

@echo %var:~-2%

The related question from which I am cobbling together the second part is this question so if this doesn't work as expected I would jump over to that one first.

Community
  • 1
  • 1
chucksmash
  • 5,777
  • 1
  • 32
  • 41
  • @user1615760 Great! You'll want to mark the answer as accepted then to let other people who find this in the future know the solution given actually works. – chucksmash Aug 22 '12 at 12:34
0

Here goes...

@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.
)
)
sparky3489
  • 99
  • 9