1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'Support' started by gschizas, Dec 7, 2013.

  1. gschizas

    Joined:
    May 30, 2008
    Messages:
    81
    Likes Received:
    0
    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)
     
  2. Charles Dye

    Charles Dye Super Moderator
    Staff Member

    Joined:
    May 20, 2008
    Messages:
    3,287
    Likes Received:
    39
    Okay, this isn't a good solution, but there's always SUBST....
     
  3. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,883
    Likes Received:
    29
    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"
     
  4. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,883
    Likes Received:
    29
    Again, a little more clearly:
    Code:
    v:\> select del ( "%@lfn["v:\Program Files (x86)"]\*" )
    Deleting V:\Program Files (x86)\foo.txt
      1 file deleted
     
  5. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,883
    Likes Received:
    29
    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"
     

Share This Page