How to? How can I use select with a folder that already contains parentheses?

May 30, 2008
80
0
Gerakas, Greece
Let's say for example that I have this command:

Code:
for /a:d %i in ("C:\Program Files (x86)\*") do echo %i

This works properly, as it should

Now I want to use the same command, only under a select command:

Code:
select ("C:\Program Files (x86)\*") do echo %i
Unfortunately, I get the error:
Code:
TCC: (Sys) The system cannot find the file specified.
 "C:\Program Files (x86"

Ok, so I'll try escaping the closing parenthesis:
Code:
C:\Users\GSchizas>select ("C:\Program Files (x86^)\*") do echo %i

No luck:
Code:
TCC: (Sys) The system cannot find the file specified.
 "C:\Program Files (x86^)\*"

Maybe escaping both?

Code:
C:\Users\GSchizas>select ("C:\Program Files ^(x86^)\*") do echo %i

Nope.

Code:
TCC: (Sys) The system cannot find the file specified.
 "C:\Program Files ^(x86^)\*"

Is there a way to do what I need?

(BTW, I'm not really trying to echo the contents of "C:\Program Files (x86)" - I'm trying to copy some files from a directory with parentheses in its name)
 
May 20, 2008
12,175
133
Syracuse, NY, USA
1. You're using SELECT wrong. It's "SELECT command ( files )".
2. This works (and I have no idea why)!
Code:
v:\> select echo ( "%@lfn["v:\Program Files (x86)"]\*" )
"V:\Program Files (x86)\foo.txt"
 
May 20, 2008
12,175
133
Syracuse, NY, USA
Again, a little more clearly:
Code:
v:\> select del ( "%@lfn["v:\Program Files (x86)"]\*" )
Deleting V:\Program Files (x86)\foo.txt
  1 file deleted
 
May 20, 2008
12,175
133
Syracuse, NY, USA
A tad more work, and a bit more elegant ...
Code:
v:\> set files="v:\Program Files (x86)\*"

v:\> select del ( %files )
Deleting V:\Program Files (x86)\foo.txt
  1 file deleted

I think Win64 has the "ProgramFiles(x86)" variable. But unfortunately, specifying "%ProgramFiles(x86)\*" won't work for the same reason the original attempt failed, because SELECT isn't very smart when it comes to handling parentheses on its command line.

If the command you're going to apply to the selected files accepts multiple filenames (see help for SELECT) on its command line (as DEL does) and you want them all processed by a single command, you can avoid the parentheses-confusion by using square brackets.
Code:
v:\> select echo [ "v:\Program Files (x86)\*" ]
"v:\Program Files (x86)\foo.txt" "v:\Program Files (x86)\foo1.txt"
 
Jun 3, 2008
137
3
Temecula, CA
My problem is related to this thread, so I thought I would add it to here. I want to use the SELECT command, but to execute a program in the Program Files (x86) folder, and using the selection part to choose which file for the program to open.

What I tried was:

select "c:\Program Files (x86)\InstallShield\DemoShield\7.5\Program\Designer.exe" %@quote[(*.dbd)]

No good. The parentheses for x86 got in the way. I also tried:


select "c:\Program Files (x86)\InstallShield\DemoShield\7.5\Program\Designer.exe" %@quote[[*.dbd]]

This failed the same way.

Short of using a SUBST or some other really ugly kludge to find a way to refer to the x86 folder, how is this done?
 
Apr 2, 2011
1,607
15
55
North Carolina, USA
set CmdToRun=c:\Program Files (x86)\InstallShield\DemoShield\7.5\Program\Designer.exe
select "%CmdToRun" (*.dbd)
 
Jun 3, 2008
137
3
Temecula, CA
Thanks, Charles. I would have thought I would need %@quote[] around the (*.dbd) part, since some of my filenames have spaces in them, but apparently the select command handles this automatically.

And I appreciate the timely support I always get from JPSoft. Thanks!
 
  • Like
Reactions: Charles G

Similar threads