Solved

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

Posted on 2004-04-30
5
741 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

757 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

23 Experts available now in Live!

Get 1:1 Help Now