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?
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.
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
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
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%)
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)
)
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)
> )
>
>
>
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)
>> )
>>
>>
>>
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
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)
> >> )
> >>
> >>
> >>
>