Solved

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

Posted on 2004-04-30
5
743 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
  • 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 125 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
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.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now