I see a few problems in spite of having no understanding of the goal.
You define a variable using SET
(e.g. SET MyFolder=
). In the Unix shells, you just say MyFOLDER=
, but not in CMD.
The IF
comparison of MYFOLDER (which should be done with ==
not =
) is probably meaningless because you're not doing it in a way that will use the contents of the variable. You're just comparing the literal string MYFOLDER
to the literal string []
. This comparison will always be false and never change throughout the course of script execution.
You are making an assignment inside parentheses (the entire contents of which are evaluated all at once, including normal variable substitution) and then attempting to access that variable inside the same "block" (CMD doesn't really have well-defined syntax, but it's at least similar to a block). What will happen is that the %z%
will be evaluated the moment the (...)
is evaluated and, in this script, it will be empty and replaced with nothing. The subsequent IF EXIST
will eat the next thing you give it, which is the parenthetical expression. I'm not able to predict what will really happen there.
I don't know why you're assigning %%B
to z
and then using z
in a comparison. Why not just use %%B
? %%B
at least will use delayed expansion.
You've enabled Delayed Expansion, but you haven't used it (except for the FOR
variable which is always delayed whether you turn on delayed expansion or not). To use delayed expansion, you have to surround the variable with bangs (!
) instead of the normal percent (%
). So, in the case of z
, or MYFOLDER
, it would become !z!
and !MYFOLDER!
respectively. Accessing variables this way is absolutely essential inside a parenthetical "block" if you assign a value to a variable within that same block.
I'd offer a revision of your script, but I'm too dull to understand what you're trying to accomplish.