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

Parenthesis concatentation problem...

Discussion in 'Support' started by mathewsdw@sbcglobal.net, Jun 16, 2009.

Thread Status:
Not open for further replies.
  1. I apologize if this question has already been answered sometime in the past, but I tried a couple of searches with no results. (I don't quite know how to search for parenthesis other than using the word "parenthesis", and that came up with no matches.) I am writing a batch file to do some simple manipulations on file names that may contain parenthesis, and this batch file is failing (dramatically in some cases) if the file name happens to contain parenthesis. Basic question can be illustrated by showing a very simple batch file (following) and its output; the same results occur if the commands in the batch file are typed in manually (but the documentation isn't nearly so good! ; > )

    Batch file contents: (It's not really as long as it at first looks since most of the lines are comments...)

    @Echo Off
    Rem First variable that is an open parenthesis...
    Set Wrk1=(
    Rem Second Variable that can be pretty much anything...
    Set Wrk2=Test
    Rem Concatenation with only one "%"...
    Rem (I know from lots of experience that this doesn't work...)
    Echo 1: %Wrk1%Wrk2
    Rem Concatenation with two "%"...
    Rem (This has always worked up to now...)
    Echo 2: %Wrk1%%Wrk2
    Rem A desperate attempt that doesn't work either...
    Echo 3: %Wrk1%%%Wrk2
    Rem This works, but it's _not_ what I want...
    Echo 4: %Wrk2%%Wrk1
    Rem Same problem with built-in functions...
    Echo 5: %Wrk1%@Right[-1,Wrk2]
    Echo 6: %Wrk1%%@Right[-1,Wrk2]
    Echo 7: %Wrk1%%%@Right[-1,Wrk2]

    Output from batch file:

    1: (Wrk2
    2: (%Wrk2
    3: (%%Wrk2
    4: Test(
    5: (@Right[-1,Wrk2]
    6: (%@Right[-1,Wrk2]
    7: (%%@Right[-1,Wrk2]

    As you can see, if a variable follows another variable that contains only an open parenthesis, the second variable does not evaluate. This is also true if the second "variable" is a built-in function. Is there a "solution" to this problem? (If not I'll have to write a C++ program to do what I want; I really don't want to go to all that trouble; that's why I write .bat files in the first place!)

    - Dan Mathews
     
  2. Steve Fabian

    Joined:
    May 20, 2008
    Messages:
    3,520
    Likes Received:
    4
    mathewsdw@sbcglobal.net wrote:
    | I apologize if this question has already been answered sometime in
    | the past, but I tried a couple of searches with no results. (I
    | don't quite know how to search for parenthesis other than using the
    | word "parenthesis", and that came up with no matches.) I am writing
    | a batch file to do some simple manipulations on file names that
    | *may* contain parenthesis, and this batch file is failing
    | (*dramatically* in some cases) if the file name happens to contain
    | parenthesis. Basic question can be illustrated by showing a very
    | simple batch file (following) and its output; the same results occur
    | if the commands in the batch file are typed in manually (but the
    | documentation isn't nearly so good! ; > )
    ...

    Did you try the /X option of the SETDOS command? I'd try setdos /x-45678. If
    that does not work for you, AND you use TCC 10 (you did not specify which
    version of the command processor you use), I would look into using the new
    binary functions, @balloc/@bread/@bwrite etc.
    --
    HTH, Steve
     
  3. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,201
    Likes Received:
    11
    I don't know why (perhaps Rex will explain) but you need to specify the
    SETDOS /X-4 command to disable nested variable expansion.

    Set Wrk1=(
    Set Wrk2=Test
    setdos /x-4
    Echo 1: %[Wrk1]%[Wrk2]
    Echo 2: %Wrk1%%Wrk2
    Echo 3: %Wrk2%%Wrk1

    -Scott


    "mathewsdw@sbcglobal.net" <> wrote on 06/16/2009
    03:06:51 AM:


     
  4. Thanks, Scott and Steve. The SETDOS command did the trick! (Phew! The files come from an external web site, I don't really have any control whatsoever about whether they contain parenthesis or not, and I really DID NOT WANT to write a C++ program! (I'm basically lazy...))

    - Dan

    P.S. By the way, I would have never in a million years looked into the "SETDOS" command (I wouldn't have even suspected that that was a configurable parameter), so THANKS AGAIN!!!

     
Thread Status:
Not open for further replies.

Share This Page