Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Passing Parameters to a batch file  (Read 35701 times)

0 Members and 1 Guest are viewing this topic.

Visual Basic

    Topic Starter


    Newbie

    • Experience: Beginner
    • OS: Unknown
    Passing Parameters to a batch file
    « on: March 20, 2011, 04:47:47 PM »
    Hi all,
    I have a master file which calls another batch file like below:

    Call "C:\CmdDest\CopyFiles.cmd"

    pause

    The CopyFiles.cmd calls this:
    xcopy "C:\Users\images\*.*" "C:\Program Files\images" /y
    pause


    xcopy "C:\Pics\*.*" "C:\Program Files\Pics" /y

    pause

    What I would like to do is instead of hard coding the  C:\Users\SunGard Branding\images\*.*, C:\Program Files\images etc I would like to pass these as Parameters from the Master file to the Child batch file...

    Please help me...

    Dundir



      Rookie

      • Yes
    • Experience: Experienced
    • OS: Windows 7
    Re: Passing Parameters to a batch file
    « Reply #1 on: March 20, 2011, 05:22:11 PM »
    Have you tried:

    Call "C:\CmdDest\Copyfiles.Cmd 'C:\Program Files\Images' 'C:\Program Files\Pics' "

    Batch parameters are saved to the variable %1,2,3,4,5,6,7,8,9 and for more than 9 you need to use SHIFT depending on OS. (i.e. OS+Command Prompt or MS-DOS)
    and

    xcopy "C:\Users\images\*.*" %1 /y
    pause

    xcopy "C:\Pics\*.*" %2 /y
    pause

    Visual Basic

      Topic Starter


      Newbie

      • Experience: Beginner
      • OS: Unknown
      Re: Passing Parameters to a batch file
      « Reply #2 on: March 20, 2011, 06:58:58 PM »
      When I do this:


      Call "C:\CmdDest\Copyfiles.Cmd 'C:\Program Files\Images' 'C:\Program Files\Pics' "


      It says the filename, directory name or volume lable syntax is incorrect

      please help

      Dundir



        Rookie

        • Yes
      • Experience: Experienced
      • OS: Windows 7
      Re: Passing Parameters to a batch file
      « Reply #3 on: March 20, 2011, 08:13:26 PM »
      Call "CopyFiles.CMD" Param1 Param2

      CopyFiles.CMD
      echo %1,  %2

      Output:
      Param1

      Looks like on my version it only passes the first variable Param1 to %1, don't know why it doesn't pass more than a single parameter.

      Update: You Could pass a single string and have CopyFiles.CMD parse that into two variables after the fact with string manipulation but thats more of an advanced topic and I still haven't gotten all the kinks out short of trimming a known part of the string out using set str=%str:~4% to assuming the first four characters need to be trimmed out.

      oldun

      • Guest
      Re: Passing Parameters to a batch file
      « Reply #4 on: March 21, 2011, 04:31:29 AM »
      Try:
      Call "C:\CmdDest\Copyfiles.Cmd" "C:\Program Files\Images" "C:\Program Files\Pics"