1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: WMIC Stump

Discussion in 'DOS/Other' started by scrfix, Jul 9, 2011.

Thread Status:
Not open for further replies.
Advertisement
  1. scrfix

    scrfix Thread Starter

    Joined:
    May 3, 2009
    Messages:
    337
    Damn,

    Going off the other post that we spoke together on from the orther forum, I tried to utilize a FOR statment for the WMIC LOGICALDISK to be able to grab the letters from there.

    I have attached the output of wmic logicaldisk>wmic.txt

    The problem I am running into is that the tokens are not always exactly the same when you do the above command. Letter C is in token 2 whereas letter D is in token 1 and letter H is back to token 2. I would like it just to output the letter. I have tried delims, the FIND command, eol=. Is there a way to do this? Example please?

    Code:
    @echo on
    set _ab=ABCDEFGHIJKLMNOPQRSTUVWXYZ
    setlocal EnableDelayedExpansion
    
    :_UsedDriveLetterCheck
    FOR /F "tokens=2*" %%I IN ('WMIC LOGICALDISK ^| FIND /I ": "') DO CALL :_UsedDriveLetterCheckProcess %%I
    GOTO _COMPLETED
     
    :_UsedDriveLetterCheckProcess
    FOR /F "tokens=1" %%I IN ("%_ab%") DO (set _ab=!_ab:%1=!)&GOTO :EOF
    GOTO :EOF
     
    :_COMPLETED
    echo %_ab%
    pause
    
     

    Attached Files:

  2. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,731
    wmic logicaldisk get deviceid
     
  3. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,731
    Code:
    @echo off
    set _ab=ABCDEFGHIJKLMNOPQRSTUVWXYZ
    setlocal EnableDelayedExpansion
    
    :_UsedDriveLetterCheck
    FOR /F "skip=1 tokens=1 delims=:" %%I IN ('WMIC LOGICALDISK get deviceid') DO set _ab=!_ab:%%I=!
    
    echo %_ab%
    On my machine I have A C D E and F. So the output is this.
    Code:
    C:\Users\Squashman>disklist.bat
    BGHIJKLMNOPQRSTUVWXYZ
     
  4. scrfix

    scrfix Thread Starter

    Joined:
    May 3, 2009
    Messages:
    337
    Thanks. I had no idea I could do the "get deviceid".
    Thanks for the example. Some times you cannot see the forest through the trees as in this case. I will using the call because I thought I needed to iterate through the string prior to removing the letters.
     
  5. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,731
    When you called that separate For Loop you were not iterating through the Alphabet. It was one big token of 26 letters. That is why I had said in a previous post to you that you didn't need the call and the second For Loop. Don't remember what thread I said that in but do remember telling you that.
     
  6. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1006524