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:
    18
    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

Ask a Question

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.