PC Review


Reply
Thread Tools Rate Thread

Batch file parameters

 
 
Vivek Srivastav
Guest
Posts: n/a
 
      28th Oct 2004
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






 
Reply With Quote
 
 
 
 
David Candy
Guest
Posts: n/a
 
      28th Oct 2004
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.
--
----------------------------------------------------------
http://www.uscricket.com
"Vivek Srivastav" <(E-Mail Removed)> wrote in message news:On%(E-Mail Removed)...
> 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
>
>
>
>
>
>

 
Reply With Quote
 
Jerold Schulman
Guest
Posts: n/a
 
      28th Oct 2004
On Thu, 28 Oct 2004 12:38:16 -0400, "Vivek Srivastav" <(E-Mail Removed)> wrote:

>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
 
Reply With Quote
 
Torgeir Bakken \(MVP\)
Guest
Posts: n/a
 
      28th Oct 2004
David Candy wrote:

> 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.


--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scr...r/default.mspx
 
Reply With Quote
 
David Candy
Guest
Posts: n/a
 
      28th Oct 2004
If you are asking how to remove the quotes change %1 and %2 to %~1 and &~2. See For command.

--
----------------------------------------------------------
http://www.uscricket.com
"David Candy" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
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.
--
----------------------------------------------------------
http://www.uscricket.com
"Vivek Srivastav" <(E-Mail Removed)> wrote in message news:On%(E-Mail Removed)...
> 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
>
>
>
>
>
>

 
Reply With Quote
 
Vivek Srivastav
Guest
Posts: n/a
 
      28th Oct 2004
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?


"Vivek Srivastav" <(E-Mail Removed)> wrote in message
news:On%(E-Mail Removed)...
> 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
>
>
>
>
>
>



 
Reply With Quote
 
Vivek Srivastav
Guest
Posts: n/a
 
      28th Oct 2004
Great.
Thanks Jerold

> 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



 
Reply With Quote
 
David Candy
Guest
Posts: n/a
 
      28th Oct 2004
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)?
--
----------------------------------------------------------
http://www.uscricket.com
"Vivek Srivastav" <(E-Mail Removed)> wrote in message news:uAM%23%(E-Mail Removed)...
> 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?
>
>
> "Vivek Srivastav" <(E-Mail Removed)> wrote in message
> news:On%(E-Mail Removed)...
>> 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
>>
>>
>>
>>
>>
>>

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Batch file: how to get all remaining parameters after a SHIFT Ronald Fischer Windows XP General 4 10th Aug 2007 11:22 AM
Batch file and string parameters brett Windows XP General 9 8th Sep 2006 12:38 AM
Calling a batch file from vb.net with parameters eric.goforth@gmail.com Microsoft VB .NET 6 15th Jun 2006 02:35 PM
Batch File Parameters =?Utf-8?B?Um9nZXI=?= Windows XP General 12 27th Jan 2006 03:19 AM
RE: Start Access from batch file with parameters =?Utf-8?B?SlVN?= Microsoft Access 0 9th Sep 2004 12:53 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:18 PM.