I'm trying to find a specfic drive using a wmic call with diskdrive and assign the deviceid as a variable. Basically I just need to look for a certain drive and make sure its not drive0. Anyway here is my code: for /f "usebackq delims== tokens=2" %x in ('wmic diskdrive where Description="Disk drive" get DeviceID /f
ormat:value') do echo %xIt seems like the '=' in Description="Disk drive" is not recognized in this for loop. The return back is blank but if I run the wmic command alone at a DOS prompt I get the reply back I'm looking for. I'm sure this is probably a syntax problem but I can not figure it out. I've tried escaping the = with \ and ^, I've double qouted the wmic string, double single quoated, and all other combinations I can think of. Please help
I had success on the command line with: for /f "tokens=2 delims==" %x in ('wmic diskdrive where "Description='Disk drive'" get DeviceID /format:value') do echo %xWhen your only tool is a hammer, every problem looks like a nail.
FWIW, I always have delims= as my last option. I think it's because I'm paranoid about delims= taking any following FOR options literally, such as taking <blank>, t, o, k, e, n, s, =, as delimiters. Whether it actually works that way, I don't know. I never wanted to find out! ;-) Also, the use of usebackq in the original code is using the intended command as a string, or this forum is displaying ` as '...
When your only tool is a hammer, every problem looks like a nail.
That worked. I thought I had to use the usebackq option because I had single quotes around the wmic call. Thanks for your help.
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |