Multi line for nested in a multi line if

Nov 8, 2012
Given the following batch file, the "for %%f in" never enters the block using TCC LE 13.04.63 on Win 7 64 bit. An old 4NT 7.00.311 works fine.

If I removed the statement if not exist %cdciBinPath%\*.* md %cdciBinPath% it works.


@echo off

set binFiles=1 2
set cdciBinPath=.\temp

if not "%binFiles%"=="" (
echo xxxxxxxxxxxxxxxxxxx
if not exist %cdciBinPath%\*.* md %cdciBinPath%
for %%f in (%binFiles%) do (
echo yyyyyyyyyyyyyyyyyyyyyy
if errorlevel 1 (
set ErrorArg=%%f
goto ErrFileMissing
goto end


Charles Dye

Super Moderator
Staff member
May 20, 2008
Albuquerque, NM
Changing the option "Duplicate CMD.EXE bugs" in the OPTIONS dialog -- first tab, right-hand column -- might help you. But I'd recommend rewriting those multi-line IF statements using IFF/ENDIFF, which is more structured and usually a better choice for complex constructs.
May 20, 2008
Elkridge, MD, USA
Using TCC/LE native syntax would provide many simplifications. Under HELP -> Conditional Expressions you find condition tests such as isdir and defined.Under MD/MKDIR you will find the /Ne option, which allows attempting to create a preexisting directory without an error message (all you care about is the result, not how you got there).

BTW, judging from the absence in the quoted code of the target label of a GOTO, it is just the segment of the batch file exhibiting the problem.