Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4029994
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:24:57+00:00 2026-05-20T11:24:57+00:00

I need to be able to pass parameters to a windows batch file BY

  • 0

I need to be able to pass parameters to a windows batch file BY NAME (and NOT by order). My purpose here is to give end user the flexibility to pass parameters in any order, and the batch file should still be able to process them.

An example to make my question clearer:

in the command line, user does the following:
somebatchfile.bat originalFile.txt newFile.txt

Inside somebatchfile.bat there is a simple statement to copy the contents of original file (first parameter %1%) to the new file (second parameter %2%). It could be as simple as the following statement:
copy %1% %2%

Now, if user passes the above parameters in reverse order, the result will be far from desirable (very WRONG in fact).

So, is there a way for user to pass parameters by name: e.g. somebatchfile.bat "SOURC=originalFile.txt" "TARGET=newFile.txt" and for script to recognize them and use’em in correct places e.g. copy %SOURCE% %TARGET%?

Thanks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T11:24:57+00:00Added an answer on May 20, 2026 at 11:24 am

    Yeah you could do something like that though I don’t think you can use “=” as a token delimiter. You could use say a colon “:”, somebatchfile.bat "SOURC:originalFile.txt" "TARGET:newFile.txt". Here is an example of how you might split the tokens:

    @echo off
    
    set foo=%1
    echo input: %foo%
    
    for /f "tokens=1,2 delims=:" %%a in ("%foo%") do set name=%%a & set val=%%b
    
    echo name:  %name%
    echo value: %val%
    

    Running this would produce this:

    C:\>test.bat SOURC:originalFile.txt
    input: SOURC:originalFile.txt
    name:  SOURC
    value: originalFile.txt
    

    [Edit]

    Ok, maybe it was too close to bed time for me last night but looking again this morning, you can do this:

    @echo off
    
    set %1
    set %2
    
    echo source: %SOURCE%
    echo target: %TARGET%
    

    Which would produce this (note that I reversed the source and target on the command line to show they are set and retrieved correctly):

    C:\>test.bat "TARGET=newFile.txt" "SOURCE=originalFile.txt"
    source: originalFile.txt
    target: newFile.txt
    

    Note that %1 and %2 are evaluated before the set so these do get set as environment variables. They must however be quoted on the command line.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to develop a file indexing application in python and wanted to know
I need to solve the following question which i can't get to work by
I am trying to load a html page through UIWebview.I need to disable all
i have a input tag which is non editable, but some times i need
This is beyond both making sense and my control. That being said here is
I have several USB mass storage flash drives connected to a Ubuntu Linux computer
Is there a way to test if a collection is already initialized? try-catch only?
We manage a site for a medical charity. They have a number of links
I have a login.jsp page which contains a login form. Once logged in the
I have a snippet to create a 'Like' button for our news site: <iframe

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.