How to? Does the "Do" command effectively do a "SetLocal/EndLocal"???

May 24, 2010
855
0
Northlake, Il
While the subject line is the primary question, there are several secondary questions here also. So getting on the point, the following very-simple batch file:
Code:
@Echo Off
SetLocal
Set I=0
Dir /K /M Q* |    ^
Do Line in @CON (
  Set /A I+=1
  @Echo I: %I  Line: %Line
)
@Echo The Final Value of I: %I
EndLocal
Quit 0

Produces the following output:
Code:
I: 2  Line: 10/22/2011  18:47            326  QQQZZ.NotNowBTM
I: 3  Line:  2/17/2011  3:30          18,943  QRSTZZ.txt
I: 4  Line: 12/19/2011  1:20            324  Quad.btm
I: 5  Line: 12/21/2011  8:08          2,152  QWETX.btm
I: 6  Line: 12/20/2011  16:17          7,417  QWETX.txt
I: 7  Line: 12/21/2011  1:19          4,393  QWETX.V2011-12-21-01-19.btm
I: 8  Line: 12/21/2011  2:01          1,742  QWETX.V2011-12-21-02-01.btm
I: 9  Line: 12/12/2011  15:14          1,697  QWRTZZ.txt
I: 0  Line:
The Final Value of I: 0

So the first and (probably most important in terms of what I am trying to accomplish) question is: What happened to what should have been the first line output? Specifically, it should be:

12/11/2011 22:36 88,822 QMGZZ.txt

And the second and third (and probably equally important in terms of what I am trying to accomplish) questions are: "Why is the final value of "I" zero outside of the loop after the loop finishes?" And if the implication of what appears to be the case from the above is the only thing I can think of that it might be, is there any way to "export" the final value of "I" outside of the "Do" loop?

The fourth question is: "How and why does "I" start out with the value "2" in what would seem must be the first line of the output?

And the fifth question is: How come there is that line whose "count" is "0" (I honestly don't see any way that a zero can be output for the "line number", ever)?

I will note two things that might be called "independent results" produce the following:

"@Echo %@Files[Q*]" simply yields the number "9".

The listing resulting from the command: "Dir /K /M Q*" contains exactly 9 lines, what you would expect given the results of "%@Files[Q*]" function, above.

What am I not understanding?

- Dan
 
Similar threads
Thread starter Title Forum Replies Date
J Take command does not start on Windows 10 Support 3
MickeyF Why does this batch file give me 'unknown command "else"' error? Support 17
M Ctrl-C when using command line history does nothing Support 2
Joe Caverly Why does TCCRT return VIEW as an internal command? Support 6
Alpengreis [v22.00.41] sync command flag "/X" does not work Support 22
E View (internal command) does nothing now Support 3
I "IF" command in a variable does not expand redirection variable name Support 0
Alpengreis WAD Command "MSGBOX /?" does not show option /N Support 2
Paul Hsieh Take Command does not launch GUI at all for me anymore. Support 3
SeoulBigChris Does TC intercept the APPEND command? Support 7
fpefpe WAD Python support does not process command line Support 14
M "V(iew)" command does not work at all for me in V13... Support 6
deleyd How does TCC search for a command? Support 2
gschizas Keyboard switching does not work in Take Command (TCMD) Support 18
D Parsing an array variable to an array does not work Support 5
J ffind does not find files Support 4
Joe Caverly PAUSE does not erase countdown timer Support 0
D ParentDirectory does not update directory history Support 6
D Documentation Help "Startup" page does not describe global lists Support 0
Charles Dye Does HASH's /E option do anything? Support 1
fishman@panix.com First TCC instantiation after reboot does not work. Support 17
D Fixed @VERSION does not increment pre-fixed version numbers. Support 1
vefatica Why does @WSLPATH double the leading '/'? Support 7
D What does the file "..\Everything\Run history.csv" store? Support 5
Peter Murschall WAD rem does not work correctly Support 8
vefatica Does @SYMLINK work? Support 6
R Tree on FAT32 does not sort by name by default. Support 6
A Tcc does not recognize "bcdedit" Support 20
vefatica JOBS /K ... how does it work? Support 5
D Does TCC improve CMD's implementation of ECHO? Support 6
vefatica Find Files/Text dialog: does it work? Support 0
Joe Caverly .PS1 script does not work with PSHELL Support 11
M MOVE does not behaves like intended (on failure) Support 1
R Fixed Sendmail parameter /USER= does not work Support 4
twaterloo does tcc have a task sceduler Support 4
Brian Woodward How to? Does FTP.CFG only support SSL over port 21? (Newbie) Support 6
M Activation Key does not correspond… Support 2
James Miller tcc shell window does not disappear Support 18
D Lua does not work on the commandline Support 5
D Fresh instance of TCMD does not use TCMD.INI Support 7
D Fixed @Lua does not behave as documented Support 8
D everything /o does not open the option dialog Support 4
M Why does HELP keep opening in the background? Support 0
vefatica Does TCC know I'm visiting the forums? Support 76
vefatica Why does my forum theme keep changing? Support 1
fishman@panix.com 19.02.37 Does Not Install For Me Support 2
I Windows 10 console does not allow alt-F4 alias to complete Support 1
fromano WAD ver /r does not detect Win 10B10166 Support 5
Alpengreis Fixed BATCOMP /O does not work Support 1
D Fixed Cut and paste in TC's file/folder view does not remove file Support 17

Similar threads