1. You are viewing our forum as a guest. For full access please Register. WindowsBBS.com is completely free, paid for by advertisers and donations.

Batch reading the label of volumes

Discussion in 'Windows XP' started by rturner, 2009/02/05.

  1. 2009/02/05
    rturner

    rturner Inactive Thread Starter

    Joined:
    2008/02/16
    Messages:
    31
    Likes Received:
    0
    Hi all,

    I need a batch file that will read the label of each volume. I really **** at batch files and any help is appreciated.

    somthing like:

    loop through volumes (e.g., a:\, c:\, d:\, e:\, etc...)
    if volume.label == "USBdrv" then
    set variable = volume (e.g., e:\)
    endif
    next
     
  2. 2009/02/05
    wildfire

    wildfire Getting Old

    Joined:
    2008/04/21
    Messages:
    4,649
    Likes Received:
    124
    It's not easy with a batch (not impossible but far from easy).

    Would a small exe file do you? I could whip up a dos exe in a couple of hours if you like?

    EDIT:
    If you'd prefer the batch route then a couple of pointers

    FIND (pipe from DIR)
    ERRORLEVEL
    FOR
     
    Last edited: 2009/02/05

  3. to hide this advert.

  4. 2009/02/05
    wildfire

    wildfire Getting Old

    Joined:
    2008/04/21
    Messages:
    4,649
    Likes Received:
    124
    OK here's what I have up till now...
    Code:
    @echo off
    if not  "%1" == " " goto checkvol
    FOR %%v 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 call %0 %%v
    :checkvol
    VOL %1: | FIND /I  "Volume in drive %1 is SYSTEM" > nul
    IF not ERRORLEVEL 1 set THEUSB=%1:\
    
    It works but it's ugly, can't recall if it's possible to redirect STDERR in dos batch commands (I'll leave that to you) ;)

    Change the SYSTEM in line 5 to whatever you're looking for and the THEUSB (line 6) to the environment variable you require.

    A couple of caveats, all volumes in the list (line 3) are checked so only the last one with the label you look for will be set...

    ie if I had a system vol on C and D the variable would be set as D. This can be changed to the first matching label if required.

    If no matching volume is found then any previous setting for the variable is kept, you may wish to clear the variable between the IF NOT and FOR.

    Let me now if that's enough for you or if you want to use exe's

    EDIT: Changed DIR to VOL (I can't beleive I forgot that command, senality setting in ;))

    Anyway the change will prevent unlikely issues with DIRCMD settings.
     
    Last edited: 2009/02/05

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.