none
Mapping Network Drives with variable(s) RRS feed

  • Question

  • Good morning,  I am attempting to use variables to xcopy files over a network to multiple computers across our network.  I can get the base to work, but the issue arises when an IP changes (we're PCI compliant, so we are not allowed access to the router to fix/assign an IP).

    the original code that worked was:

    xcopy "F:\Store Back Ups\OutBound To Stores\BackUpHistory" "\\10.180.16.95\BackUpHistory" /i /d /e /y /v /j /z >> logfile

    xcopy "F:\Store Back Ups\OutBound To Stores\BackUpHistory" "\\10.180.17.95\BackUpHistory" /i /d /e /y /v /j /z >> logfile

    Objective:

    I'd like to set the variable through the batch file that I use to perform the xcopy.

    I have tried several variations of the below to attempt to set a variable at the start of the batch file 
    set STORE016=10.180.16.95
    set STORE017=10.180.17.79

    The code that I used with the variables would be:

    xcopy "F:\Store Back Ups\OutBound To Stores\BackUpHistory" "\\STORE016\BackUpHistory" /i /d /e /y /v /j /z >> logfile

    xcopy "F:\Store Back Ups\OutBound To Stores\BackUpHistory" "\\STORE017\BackUpHistory" /i /d /e /y /v /j /z >> logfile

    When I try this, I keep getting an invalid message...

    Help to get this going would be appreciated.

    Thank you,

    K.

    Thursday, October 17, 2019 4:45 AM

Answers

  • 1) In your SET commands, make SURE not to have any spaces around the = sign:


    set STORE016=10.180.16.95

    (Note there are no spaces surrounding the = sign.)

    2) To use an variable in a command, you must surround it with % signs:


    xcopy F:\.... \\%STORE016%\...


    -- Bill Stewart [Bill_Stewart]


    Thursday, October 17, 2019 1:23 PM
    Moderator