Problem using SET command in CMD file

SOLVED Discussion in 'General Discussion' started by jepollard, Jun 9, 2017.

  1. jepollard

    jepollard

    Joined:
    May 16, 2017
    Messages:
    8
    Likes Received:
    0
    I have a CMD file used to create backups from my C: drive to a user-designated USB drive. The fundamentals are working fine, but a small refinement I'd like to add is giving me a problem.

    At the beginning of the CMD, I get the port where the USB device is located using the SET /p new_variable= construct: this works fine.

    Say the name of this variable is M_drive1 (the drive letter).

    Later I create another new_variable (to use in the XCOPY command that does the actual "backup"). That new_variable is created using this construct: SET M_outdrive=%M_drive1%:?

    So if the user enters "m" (no quotes) to the request for drive letter, then M_drive1 contains the letter m, and M_outdrive contains m:\.

    The CMD file then verifies that the named drive is valid (exists) and aborts if not.

    All the above works as intended.

    At this point I'd like to display the USB disk volume label. So I want to create a variable to pass to the Vol command. For that I use the command: SET M_vol=%M_drive1%:.

    But that creates a variable M_vol that just contains the colon ... no drive letter.

    Can someone tell me what I'm doing wrong?
     
    jepollard, Jun 9, 2017
    #1
    1. Advertisements

  2. jepollard

    jepollard

    Joined:
    May 16, 2017
    Messages:
    8
    Likes Received:
    0
    I forgot to add: I'm running 64 bit Windows 7 Pro.
     
    Last edited: Jun 9, 2017
    jepollard, Jun 9, 2017
    #2
    1. Advertisements

  3. jepollard

    John700

    Joined:
    Jun 17, 2017
    Messages:
    17
    Likes Received:
    0
    I think I know what you are trying to do, but explaining all in pure text seems to make it harder to understand. Can you just put the exact code, or similar code ?
     
    John700, Jun 18, 2017
    #3
  4. jepollard

    jepollard

    Joined:
    May 16, 2017
    Messages:
    8
    Likes Received:
    0
    I appreciate your offer to help.

    As sometimes happens, when I was in the process of selecting the code to post here, I discovered the cause of the problem: I had used the wrong variable in the SET command.
    And the underlying cause of that was mistaking the number "1" for a lower case "l". My bad, sorry.
    Once I corrected the variable name, the SET command worked as I intended.
     
    jepollard, Jun 19, 2017
    #4
    1. Advertisements

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. teg1545

    move from cmd.exe 32 bit to cmd.exe 64 bit

    teg1545, Oct 12, 2010, in forum: Windows 7 Support
    Replies:
    2
    Views:
    3,471
    teg1545
    Oct 12, 2010
  2. sagngh8pro
    Replies:
    0
    Views:
    1,222
    sagngh8pro
    Jun 6, 2011
  3. JETKING

    shutdown using CMD

    JETKING, Jun 28, 2011, in forum: alt.windows7.general
    Replies:
    16
    Views:
    2,376
    jeepers
    Jul 5, 2011
  4. fenhopi

    Using CMD do deactivate cpanel access

    fenhopi, Aug 8, 2012, in forum: Customization
    Replies:
    1
    Views:
    1,513
    TrainableMan
    Aug 8, 2012
  5. mark dib

    cmd command

    mark dib, Nov 7, 2012, in forum: Software
    Replies:
    1
    Views:
    1,114
    TrainableMan
    Nov 7, 2012
  6. l.hilger

    .bat file and two commands in one cmd line

    l.hilger, Dec 20, 2012, in forum: Windows 7 Support
    Replies:
    9
    Views:
    2,966
    TrainableMan
    Dec 23, 2012
  7. mtsgill
    Replies:
    0
    Views:
    784
    mtsgill
    Mar 6, 2013
  8. RITESH
    Replies:
    2
    Views:
    282
    Lance1
    Feb 5, 2017
Loading...