"for" in multiple lines

LuP

Oct 4, 2011
18
0
Hello,

I encountered the following difference between TC*.exe and cmd.exe when processing a bat file with a for-loop parameters divided into more lines:

Code:
for %%j in (~
            ~Scr) do (

  rd /q /s .\%%j

)

The cmd.exe gives:

Code:
C:\Lukas\~\Cpp~~>cmd
Microsoft Windows XP [Verze 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Lukas\~\Cpp~~>t.bat

C:\Lukas\~\Cpp~~>for %j in (~ ~Scr) do (rd /q /s .\%j )

C:\Lukas\~\Cpp~~>(rd /q /s .\~ )
Systém nemůže nalézt uvedený soubor. (= System cannot find the specified file.)

C:\Lukas\~\Cpp~~>(rd /q /s .\~Scr )
Systém nemůže nalézt uvedený soubor. (= System cannot find the specified file.)

C:\Lukas\~\Cpp~~>

whilst TC*.exe gives:

Code:
C:\Lukas\~\Cpp~~>t.bat
for %%j in (~
C:\Lukas\~\Cpp~~\t.bat [1]  Usage : FOR [/A:[[-][+]rhsdaecjot] /D /F ["options"] /H /I"text" /L /Nj /O:[-]adegnrstu /R [path] /T"..." /W] %var IN ([@]set | start, step, end) [DO] command ..
~Scr) do (
TCC: C:\Lukas\~\Cpp~~\t.bat [2]  Unknown command "~Scr)"
rd /q /s .\%j
TCC: (Sys) C:\Lukas\~\Cpp~~\t.bat [4]  Neplatný název adresáře. (= Invalid name of a directory.)
 "C:\Lukas\~\Cpp~~\%j"
)
TCC: C:\Lukas\~\Cpp~~\t.bat [6]  Unknown command ")"

C:\Lukas\~\Cpp~~>

This is just a sample - normally I have the line divided into more lines as it uses many parameters:

Code:
...
    for %%j in (~
                ~Scr Scr~ ~Scr.AxE Scr~.AxE ~Scr.Off Scr~.Off ~Scr.Srf Scr~.Srf
                DXF~ DXF~.AxE DXF~.Srf DXF~.Off
                ~Drawings Drawings~ Drawings.~ Drawings.~~
                ~Test Test.~
                Funs~ Tables~
                ~.plt) do (

      rd /q /s %%i\%%j

    )
...

So my question is - how to make TC* treat for-loop parameters divided into more lines the same way as cmd.exe does?

TIA.

LuP
 

rconn

Administrator
Staff member
May 14, 2008
12,344
149
Hello,

I encountered the following difference between TC*.exe and cmd.exe when processing a bat file with a for-loop parameters divided into more lines:

Code:
for %%j in (~
            ~Scr) do (
 
  rd /q /s .\%%j
 
)

There are two documented ways of doing this in CMD and TCC; you're using a third undocumented approach that only works in certain versions of CMD. (And only because CMD has a separate incompatible parser for the FOR command.)

The preferred ways of doing it are either:

Code:
for %%j in (~ ~Scr) do (
 
  rd /q /s .\%%j
 
)

where the open command group '(' at the end of the first line tells FOR to look for the closing ')'. (IMO this is the much more readable format.)

Alternatively, you can add an escape at the end of the line, which tells TCC (and CMD) that the command is continued on the next line:

Code:
for %%j in (~^
    ~Scr) do (
 
  rd /q /s .\%%j
 
)
 

LuP

Oct 4, 2011
18
0
OK, thanks.

Alternatively, you can add an escape at the end of the line, which tells TCC (and CMD) that the command is continued on the next line:

Code:
for %%j in (~^
    ~Scr) do (
 
  rd /q /s .\%%j
 
)

In your proposal the divided text yields "~~Scr" (= just one parameter) whilst

Code:
for %%j in (~ ^
    ~Scr) do (
 
  rd /q /s .\%%j
 
)

gives "~" and "~Scr" (= two parameters; as wanted originally).

Thanks again.

LuP
 
Similar threads
Thread starter Title Forum Replies Date
samintz How to? Pull out multiple matching lines Support 5
MickeyF TCC crashing when copying multiple files (now resolved) Support 6
N Unable to bind multiple keys to the same key mapping directive Support 9
vefatica Console not redrawn in BTM or with multiple commands Support 4
C duplicate files in multiple plugin sites Support 9
kb6ojs ALIAS with multiple commands? Support 9
vefatica How do I do this with a multiple-line DO? Support 7
Joe Caverly Multiple Text Searches at once using FFIND or TPIPE Support 4
R How to? Append files in multiple subfolders using copy? Support 8
N multiple command alias and redirection Support 0
B Can copy command concatenate multiple mp3 files Support 2
C INSTALLED returnes same program multiple times Support 14
M Delete multiple Alternate Datastreams Support 5
D What are the rules for detecting multiple versions of TC on a machine? Support 7
C FOLDERMONITOR inactive with multiple /I Support 1
C WAD VIEW print multiple files - switches fail Support 10
vefatica Multiple instances of help file Support 3
J How to? Array sort according to multiple keys Support 3
Alexander WAD The number of files and dirs are multiplied when using multiple wildcards Support 6
Jay Sage Version 17 Installer Leaves Multiple Copies of ShrAlias Support 48
R Fixed Internal ZIP command fails to process multiple files Support 3
M How to? PDir on multiple wildcard patterns... Support 2
A WAD Dir daterange + multiple path wildcards crashes tcc Support 2
T How to? Using FOLDERMONITOR 1 event causes multiple trigger(ing)s Support 8
D WAD Multiple TEE causese weird variable scoping? Support 7
S TAR with multiple files and /G Support 2
Frank VIEWing multiple files possible? Support 4
J syntax problems multiple commands (command & command) Support 4
J How do I - ffind - with multiple items Support 10
R multiple monitor 'help' Support 7
H Another multiple FTP password prompt issue Support 2
J tcmd height with multiple monitors Support 2
T Open & Configure multiple TCC windows on STARTUP Support 4
vefatica Continued lines (^) in a library routine? Support 5
R Lines between COMMENT & ENDCOMMENT not ignored Support 7
A TCMD - Dir Command puts out blank lines? Support 16
T FFind - can we display n number of lines after the find? Support 2
T WAD Difference between TCC and CMD in handling multi-command lines Support 6
JohnQSmith Weird DIR output (missing lines) Support 1
fpefpe Documentation Comment lines? Support 2
nickles Fixed Executing long command lines in a batch generates file name errors Support 16
B %@lines doesn't count last line without cr/lf at eof Support 1
nikbackm How to? Find duplicate lines in text file Support 0
S Documentation HELP nit: @LINES Support 5
B Select and run lines from Command Input panel? Support 1
D WAD New envars for @LINES are not hidden Support 8
T Documentation @LINE[CON,n] @LINES[CON] not documented (bug?) Support 4
M How to? Parsing lines containing double quotes... Support 3
Stefano Piccardi echoerr truncates long lines Support 9
M Just an out-of-curiosity question the List command vs. the @Lines function... Support 13

Similar threads