HTFC Forums

H.T.F.C.

How To Fix Computers





Go Back   HTFC Forums > Software Newsgroups > Windows XP

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
  #1  
Old 03-28-2008, 12:49 AM
WB
 
Posts: n/a
Default Any way to escape parenthesis characters in a batch file?

if "%PROCESSOR_ARCHITECTURE%"=="x86" (
set PROGNAME=Program Files
) else if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
set PROGNAME=Program Files (x86)
)

This fails because of the parenthesis in (x86). I have a workaround already,
but I'd prefer using the method above for readability. Any way to escape the
parenthesis characters so this will work?

--
Bill Baker
Reply With Quote
Sponsored Links
Fix your Windows Problems - FAST.
FREE Safe Scan Registry Check. Locate & Fix Errors in Minutes!
  #2  
Old 03-28-2008, 01:14 AM
Big Al
 
Posts: n/a
Default Re: Any way to escape parenthesis characters in a batch file?

WB wrote:
> if "%PROCESSOR_ARCHITECTURE%"=="x86" (
> set PROGNAME=Program Files
> ) else if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
> set PROGNAME=Program Files (x86)
> )
>
> This fails because of the parenthesis in (x86). I have a workaround already,
> but I'd prefer using the method above for readability. Any way to escape the
> parenthesis characters so this will work?
>

I didn't think .bat files would accept if/else commands.
I know 'if exists ... goto' works. I use it to skip to another line in
a batch file, and thus the next line is the else.
But not much else you can do.
Reply With Quote
  #3  
Old 03-28-2008, 01:20 AM
Colin Barnhorst
 
Posts: n/a
Default Re: Any way to escape parenthesis characters in a batch file?

Can you use the short file name for Program Files (x86)? It is "PROGRA~2".
Or is that your workaround?

"WB" <WB@discussions.microsoft.com> wrote in message
news:C713DAEC-73F3-42FB-ABE5-6EFB594BC3E1@microsoft.com...
> if "%PROCESSOR_ARCHITECTURE%"=="x86" (
> set PROGNAME=Program Files
> ) else if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
> set PROGNAME=Program Files (x86)
> )
>
> This fails because of the parenthesis in (x86). I have a workaround
> already,
> but I'd prefer using the method above for readability. Any way to escape
> the
> parenthesis characters so this will work?
>
> --
> Bill Baker


Reply With Quote
  #4  
Old 03-28-2008, 01:21 AM
Big Al
 
Posts: n/a
Default Re: Any way to escape parenthesis characters in a batch file?

WB wrote:
> if "%PROCESSOR_ARCHITECTURE%"=="x86" (
> set PROGNAME=Program Files
> ) else if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
> set PROGNAME=Program Files (x86)
> )
>
> This fails because of the parenthesis in (x86). I have a workaround already,
> but I'd prefer using the method above for readability. Any way to escape the
> parenthesis characters so this will work?
>

see http://home7.inet.tele.dk/batfiles/batfiles.htm
I was partially right. Use the GOTO to get to another line of code

if ........... goto OKAY
rem here if IF is false
goto END

:OKAY
rem here if IF is true
goto END


:END
rem here on both.
Reply With Quote
  #5  
Old 03-28-2008, 07:01 AM
Pegasus \(MVP\)
 
Posts: n/a
Default Re: Any way to escape parenthesis characters in a batch file?


"Big Al" <BigAl@nowhere.com> wrote in message
news:JLWGj.9189$Oj5.1280@trnddc06...
> WB wrote:
>> if "%PROCESSOR_ARCHITECTURE%"=="x86" (
>> set PROGNAME=Program Files
>> ) else if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
>> set PROGNAME=Program Files (x86)
>> )
>>
>> This fails because of the parenthesis in (x86). I have a workaround
>> already, but I'd prefer using the method above for readability. Any way
>> to escape the parenthesis characters so this will work?
>>

> I didn't think .bat files would accept if/else commands.
> I know 'if exists ... goto' works. I use it to skip to another line in a
> batch file, and thus the next line is the else.
> But not much else you can do.


They actually do. Try this for fun:

@echo off
if %UserName%==Al (echo Hello Al) else (echo Goodby %Username%)


Reply With Quote
  #6  
Old 03-28-2008, 07:03 AM
Pegasus \(MVP\)
 
Posts: n/a
Default Re: Any way to escape parenthesis characters in a batch file?


"WB" <WB@discussions.microsoft.com> wrote in message
news:C713DAEC-73F3-42FB-ABE5-6EFB594BC3E1@microsoft.com...
> if "%PROCESSOR_ARCHITECTURE%"=="x86" (
> set PROGNAME=Program Files
> ) else if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
> set PROGNAME=Program Files (x86)
> )
>
> This fails because of the parenthesis in (x86). I have a workaround
> already,
> but I'd prefer using the method above for readability. Any way to escape
> the
> parenthesis characters so this will work?
>
> --
> Bill Baker


Try this:
@echo off
if "%PROCESSOR_ARCHITECTURE%"=="x86" (
set PROGNAME=Program Files
) else (
if "%PROCESSOR_ARCHITECTURE%"=="AMD64" set PROGNAME=Program Files (x86)
)


Reply With Quote
  #7  
Old 03-28-2008, 06:40 PM
WB
 
Posts: n/a
Default Re: Any way to escape parenthesis characters in a batch file?

This is pretty much the same code I had. Unfortunately it sets PROGNAME as
"Program Files (x86" with the missing closed parenthesis.

My workaround is as follows:
SET PROGNAME=Program Files (x86)
IF "%PROCESSOR_ARCHITECTURE%"=="x86" SET PROGNAME=Program Files

This will also work if PROCESSOR_ARCHITECTURE changes to "AMD128", or
"Intel128" like it should be .
--
Bill Baker


"Pegasus (MVP)" wrote:

>
> "WB" <WB@discussions.microsoft.com> wrote in message
> news:C713DAEC-73F3-42FB-ABE5-6EFB594BC3E1@microsoft.com...
> > if "%PROCESSOR_ARCHITECTURE%"=="x86" (
> > set PROGNAME=Program Files
> > ) else if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
> > set PROGNAME=Program Files (x86)
> > )
> >
> > This fails because of the parenthesis in (x86). I have a workaround
> > already,
> > but I'd prefer using the method above for readability. Any way to escape
> > the
> > parenthesis characters so this will work?
> >
> > --
> > Bill Baker

>
> Try this:
> @echo off
> if "%PROCESSOR_ARCHITECTURE%"=="x86" (
> set PROGNAME=Program Files
> ) else (
> if "%PROCESSOR_ARCHITECTURE%"=="AMD64" set PROGNAME=Program Files (x86)
> )
>
>
>

Reply With Quote
  #8  
Old 03-28-2008, 07:05 PM
Colin Barnhorst
 
Posts: n/a
Default Re: Any way to escape parenthesis characters in a batch file?

You never did comment on whether "progra~2" could work for you. Can't you
use the short filename?

"WB" <WB@discussions.microsoft.com> wrote in message
news:C49F7B14-DDF4-4F6E-9BF6-5153E3F81854@microsoft.com...
> This is pretty much the same code I had. Unfortunately it sets PROGNAME as
> "Program Files (x86" with the missing closed parenthesis.
>
> My workaround is as follows:
> SET PROGNAME=Program Files (x86)
> IF "%PROCESSOR_ARCHITECTURE%"=="x86" SET PROGNAME=Program Files
>
> This will also work if PROCESSOR_ARCHITECTURE changes to "AMD128", or
> "Intel128" like it should be .
> --
> Bill Baker
>
>
> "Pegasus (MVP)" wrote:
>
>>
>> "WB" <WB@discussions.microsoft.com> wrote in message
>> news:C713DAEC-73F3-42FB-ABE5-6EFB594BC3E1@microsoft.com...
>> > if "%PROCESSOR_ARCHITECTURE%"=="x86" (
>> > set PROGNAME=Program Files
>> > ) else if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
>> > set PROGNAME=Program Files (x86)
>> > )
>> >
>> > This fails because of the parenthesis in (x86). I have a workaround
>> > already,
>> > but I'd prefer using the method above for readability. Any way to
>> > escape
>> > the
>> > parenthesis characters so this will work?
>> >
>> > --
>> > Bill Baker

>>
>> Try this:
>> @echo off
>> if "%PROCESSOR_ARCHITECTURE%"=="x86" (
>> set PROGNAME=Program Files
>> ) else (
>> if "%PROCESSOR_ARCHITECTURE%"=="AMD64" set PROGNAME=Program Files
>> (x86)
>> )
>>
>>
>>


Reply With Quote
  #9  
Old 03-28-2008, 07:16 PM
Pegasus \(MVP\)
 
Posts: n/a
Default Re: Any way to escape parenthesis characters in a batch file?

My suggestion may have been pretty much the same as
your own code, with a slight difference: It was able to handle
if-then-else statements. Your work-around is, of course,
an excellent alternative solution.


"WB" <WB@discussions.microsoft.com> wrote in message
news:C49F7B14-DDF4-4F6E-9BF6-5153E3F81854@microsoft.com...
> This is pretty much the same code I had. Unfortunately it sets PROGNAME as
> "Program Files (x86" with the missing closed parenthesis.
>
> My workaround is as follows:
> SET PROGNAME=Program Files (x86)
> IF "%PROCESSOR_ARCHITECTURE%"=="x86" SET PROGNAME=Program Files
>
> This will also work if PROCESSOR_ARCHITECTURE changes to "AMD128", or
> "Intel128" like it should be .
> --
> Bill Baker



Reply With Quote
  #10  
Old 03-28-2008, 09:58 PM
WB
 
Posts: n/a
Default Re: Any way to escape parenthesis characters in a batch file?

The short filename method may work as well, but I prefer my workaround method
just for clean-looking code. Plus I just have a deep hatred for short
filenames, and there's always that one-in-a-million chance that something
will happen to make it "progra~3". We had an issue recently where a DOS
program had to look for a text file. A backup of the file had been made, and
somehow the two short filenames got switched, causing the DOS app to fail.
--
Bill Baker


"Colin Barnhorst" wrote:

> You never did comment on whether "progra~2" could work for you. Can't you
> use the short filename?
>
> "WB" <WB@discussions.microsoft.com> wrote in message
> news:C49F7B14-DDF4-4F6E-9BF6-5153E3F81854@microsoft.com...
> > This is pretty much the same code I had. Unfortunately it sets PROGNAME as
> > "Program Files (x86" with the missing closed parenthesis.
> >
> > My workaround is as follows:
> > SET PROGNAME=Program Files (x86)
> > IF "%PROCESSOR_ARCHITECTURE%"=="x86" SET PROGNAME=Program Files
> >
> > This will also work if PROCESSOR_ARCHITECTURE changes to "AMD128", or
> > "Intel128" like it should be .
> > --
> > Bill Baker
> >
> >
> > "Pegasus (MVP)" wrote:
> >
> >>
> >> "WB" <WB@discussions.microsoft.com> wrote in message
> >> news:C713DAEC-73F3-42FB-ABE5-6EFB594BC3E1@microsoft.com...
> >> > if "%PROCESSOR_ARCHITECTURE%"=="x86" (
> >> > set PROGNAME=Program Files
> >> > ) else if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
> >> > set PROGNAME=Program Files (x86)
> >> > )
> >> >
> >> > This fails because of the parenthesis in (x86). I have a workaround
> >> > already,
> >> > but I'd prefer using the method above for readability. Any way to
> >> > escape
> >> > the
> >> > parenthesis characters so this will work?
> >> >
> >> > --
> >> > Bill Baker
> >>
> >> Try this:
> >> @echo off
> >> if "%PROCESSOR_ARCHITECTURE%"=="x86" (
> >> set PROGNAME=Program Files
> >> ) else (
> >> if "%PROCESSOR_ARCHITECTURE%"=="AMD64" set PROGNAME=Program Files
> >> (x86)
> >> )
> >>
> >>
> >>

>

Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
stopping a batch file if a file isn't found yawnmoth Windows XP 3 02-15-2008 09:23 PM
Batch file works in command line but not as a batch Danger Windows XP 7 02-05-2008 04:50 PM
Foreign-language characters in batch file command path hmm Windows XP 0 01-10-2008 12:51 PM
Square characters in file name -DLynn Windows Vista 0 05-23-2007 10:35 PM
How do you copy a shortcut to a file with a batch file? Pegasus \(MVP\) Windows XP 11 04-13-2007 10:56 PM


All times are GMT. The time now is 09:09 AM.


Powered by vBulletin® Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© 2004 - 2007 Web-S-Sense Pty. Ltd. Usenet and forums posts © their respective authors.
Ad Management by RedTyger