M
[email protected]
Guest
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
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