?
Solved

concatenation of all parameters (%1 %2) in a .bat file

Posted on 2004-04-30
5
Medium Priority
?
755 Views
Last Modified: 2010-05-18
I know this is possible but don't remember how
I have a script.bat that can accept a lot of parms (more than 10)
I need inside the script to build a variable, says P which will contain all these parameters concatenated.
SO P=%1 %2 %3 ... will work but how to build it with more (undetermined number) than 9 parameters
0
Comment
Question by:LeTay
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 10957758
You'll need to use SHIFT
>>
Changes the position of replaceable parameters in a batch file.

SHIFT [/n]

If Command Extensions are enabled the SHIFT command supports
the /n switch which tells the command to start shifting at the
nth argument, where n may be between zero and eight.  For example:

    SHIFT /2

would shift %3 to %2, %4 to %3, etc. and leave %0 and %1 unaffected.
<<
0
 

Author Comment

by:LeTay
ID: 10957799
I know that shift command, but practically how do I do ?
Assume sample.bat is the batch which need to set P to all argument passed
What is the cod in sample.bat to achieve this ?
0
 

Author Comment

by:LeTay
ID: 10957814
.../...
In fact how to I loop correctly ?
I suppose I write something like

set P=
.../...
:loop
set P=%P% %1
shift
goto loop
:end

But how to stop the loop ?
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 10958133
Looks like you've got the general idea...
Just need to place a
 if [%1]=[] goto end
in there...
0
 
LVL 9

Expert Comment

by:ankuratvb
ID: 10958326
I guess this is what SB is talking about:

@ECHO OFF
:GETFILE
SHIFT
IF "%1"=="" GOTO END

GOTO GETFILE
:END

0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question