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

  • Home
  • SEARCH
  • 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 3942736
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:41:55+00:00 2026-05-20T00:41:55+00:00

Is it possible to filter list of arguments in windows batch file? Assuming it

  • 0

Is it possible to filter list of arguments in windows batch file?

Assuming it is called like:

file.cmd arg1 --unwanted arg3

It should call some other executable (hardcoded) without the argument string --unwanted:

some.exe arg1 arg3

I only know the name of the argument, it can be passed as any argument in the list. It may not exist on argument list, and the all arguments should be passed unmodified. Number of arguments may vary.

More examples (what’s called -> what should be called in result)

file.cmd arg1 arg2 -> some.exe arg1 arg2
file.cmd --unwanted -> some.exe
file.cmd --unwanted arg2 -> some.exe arg2
file.cmd arg1 --unwanted -> some.exe arg1

Moving from unix shell scripting windows batch files are black magic to me 🙂

  • 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-20T00:41:56+00:00Added an answer on May 20, 2026 at 12:41 am
    @echo off
    setlocal ENABLEEXTENSIONS
    
    if "%1"=="SOTEST" (
        REM tests...
        call file.cmd arg1 --unwanted arg3
        call file.cmd arg1 arg2
        call file.cmd --unwanted
        call file.cmd --unwanted arg2
        call file.cmd arg1 --unwanted
        goto :EOF
    )
    
    set params=
    :nextparam
    if "%~1"=="--unwanted" (shift&goto nextparam)
    if not "%~1"=="" (set "params=%params%%1 "&shift&goto nextparam)
    
    echo.%*^>^>%params%
    

    This prints:

    arg1 --unwanted arg3>>arg1 arg3
    arg1 arg2>>arg1 arg2
    --unwanted>>
    --unwanted arg2>>arg2
    arg1 --unwanted>>arg1
    

    Edit:

    @echo off
    setlocal ENABLEEXTENSIONS
    
    if "%~1"=="SOTEST" (
        REM tests...
        call file.cmd arg1=foo --unwanted arg3=bar
        call file.cmd arg1 arg2
        call file.cmd --unwanted
        call file.cmd --unwanted arg2
        call file.cmd arg1 --unwanted
        call file.cmd "arg1" --unwanted "arg3"
        call file.cmd "arg1=foo" --unwanted arg3="bar"
        goto :EOF
    )
    
    set var=0
    set params=
    :nextparam
    set /A var=%var% + 1
    for /F "tokens=%var% delims= " %%A in ("%*") do (
        if not "%%~A"=="--unwanted" set "params=%params%%%A "
        goto nextparam
    )
    
    echo.%*^>^>%params%
    

    prints

    arg1=foo --unwanted arg3=bar>>arg1=foo arg3=bar
    arg1 arg2>>arg1 arg2
    --unwanted>>
    --unwanted arg2>>arg2
    arg1 --unwanted>>arg1
    "arg1" --unwanted "arg3">>"arg1" "arg3"
    "arg1=foo" --unwanted arg3="bar">>"arg1 foo" arg3="bar"
    

    meaning “arg1=foo” is broken, you can switch the for loop to for /F "tokens=%var% delims= " %%A in ('echo.%*') do ( to get it working, but that breaks arg1=foo and arg3=”bar”

    This is a known problem with batch files, once you start messing with strings things are going to get screwed up in some configuration since there is always some character that is going to mess things up (%,!,”,^,&,|,<,>,space etc)

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

Sidebar

Related Questions

In Eclipse (Galileo) is it possible to filter the list of TODO and FIXME
Is it possible to filter the displayed changed files list for a selected revision?
Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should
Possible Duplicate: Singleton: How should it be used Following on from Ewan Makepeace 's
Is it possible to get the value of the dynamic filter input into a
I have a list of about 20 products, each with up to 30 possible
I'd like to leverage the built-in intent chooser to display a custom filtered list
Possible Duplicate: NAnt or MSBuild, which one to choose and when? What is the
Possible Duplicate: How do I calculate someone's age in C#? Maybe this could be
Possible Duplicate: .NET - What’s the best way to implement a catch all exceptions

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.