Batch file parameters

V

Vivek Srivastav

How can I pass multiple long file names to batch files:

test.bat "C:\Program Files\test" "c:\Program Files\Another Dir"


I want the following result in the batch file
echo %1 should give me: C:\Program Files\test
echo %2 should give me: C:\Program Files\Another Dir

Is there some way this can be done?

thanks
vivek
 
D

David Candy

Just as you said. Why did you bother asking?

C:\>"C:\Documents and Settings\David Candy\Desktop\New Text Document (2).bat" "C:\Documents and Settings\David Candy\Desktop\n
ewrast.pdf" "C:\Documents and Settings\David Candy\Desktop\newmccarthy.pdf"

C:\>echo "C:\Documents and Settings\David Candy\Desktop\newrast.pdf"
"C:\Documents and Settings\David Candy\Desktop\newrast.pdf"

C:\>echo "C:\Documents and Settings\David Candy\Desktop\newmccarthy.pdf"
"C:\Documents and Settings\David Candy\Desktop\newmccarthy.pdf"

I duplicated it because I thought it was a trick question.
 
J

Jerold Schulman

How can I pass multiple long file names to batch files:

test.bat "C:\Program Files\test" "c:\Program Files\Another Dir"


I want the following result in the batch file
echo %1 should give me: C:\Program Files\test
echo %2 should give me: C:\Program Files\Another Dir

Is there some way this can be done?

thanks
vivek

test.bat "C:\Program Files\test" "c:\Program Files\Another Dir" [more]

Test.bat contains:
@echo off
if {%1}=={} @echo Syntax: Test Obj1 [Obj2 .... ObjN]&goto :EOF
setlocal
:loop
if {%1}=={} endlocal&goto :EOF
set Obj=%1
shift
set Obj=%Obj:"=%
@echo %Obj%
goto loop


Jerold Schulman
Windows: General MVP
JSI, Inc.
http://www.jsiinc.com
 
T

Torgeir Bakken \(MVP\)

David said:
Just as you said. Why did you bother asking?

C:\>"C:\Documents and Settings\David Candy\Desktop\New Text Document (2).bat" "C:\Documents and Settings\David Candy\Desktop\n
ewrast.pdf" "C:\Documents and Settings\David Candy\Desktop\newmccarthy.pdf"

C:\>echo "C:\Documents and Settings\David Candy\Desktop\newrast.pdf"
"C:\Documents and Settings\David Candy\Desktop\newrast.pdf"

C:\>echo "C:\Documents and Settings\David Candy\Desktop\newmccarthy.pdf"
"C:\Documents and Settings\David Candy\Desktop\newmccarthy.pdf"

I duplicated it because I thought it was a trick question.
Hi

Note that the OP's echo examples are without double quote characters.
The script in Jerold's post removes those before displaying the paths.
 
D

David Candy

If you are asking how to remove the quotes change %1 and %2 to %~1 and &~2. See For command.

--
----------------------------------------------------------
http://www.uscricket.com
Just as you said. Why did you bother asking?

C:\>"C:\Documents and Settings\David Candy\Desktop\New Text Document (2).bat" "C:\Documents and Settings\David Candy\Desktop\n
ewrast.pdf" "C:\Documents and Settings\David Candy\Desktop\newmccarthy.pdf"

C:\>echo "C:\Documents and Settings\David Candy\Desktop\newrast.pdf"
"C:\Documents and Settings\David Candy\Desktop\newrast.pdf"

C:\>echo "C:\Documents and Settings\David Candy\Desktop\newmccarthy.pdf"
"C:\Documents and Settings\David Candy\Desktop\newmccarthy.pdf"

I duplicated it because I thought it was a trick question.
 
V

Vivek Srivastav

It was not a trick question:
When I run the following command on XP with SP2 I get the following output:

F:\>installCMS.bat "c:\Program Files\Java\j2re1.4.2_04" "f:\Cjava\CMS"

output:

Files\Java\j2re1.4.2_04"" was unexpected at this time.

Following is the script:

@echo JAVA_HOME: %1
@echo CMS_HOME: %2

If it is working for you, why is it not working for me?
 
D

David Candy

C:\>"C:\Documents and Settings\David Candy\Desktop\installCMS.bat" "c:\Program Files\Java\j2re1.4.2_04" "f:\Cjava\CMS"
JAVA_HOME: "c:\Program Files\Java\j2re1.4.2_04"
CMS_HOME: "f:\Cjava\CMS"

Is what should happen. Regardless you shouldn't be getting this error at all. Is there anything else in your batch file (as it not really useful as is). I suspect a program in your bat file is raising the error. Just confirm the error has two trailing quotes (inverted commas). You are cutting and pasting and not typing (in the post) the output, command line, and batch code (right click title bar then Edit to cut and paste)?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top