Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

(Somewhat unbelievable) Do While Behavior/Question

Here is a small .bat file that works as expected:

On Break GoTo Finish
SetLocal
For /R C:\Windows /D %E in (*) Do (
Echo %E
)
:Finish
EndLocal
Quit 0

The output from this .bat file is a list of Windows directories and their subdirectories.

Following is a some-what modified version of above (and an example from a "real" .bat file):

On Break GoTo Finish
SetLocal
Set S=C:\Windows
For /R %S /D %E in (*) Do (
Echo %E
)
:Finish
EndLocal
Quit 0

Here is the output from "sample" .bat file:

On Break GoTo Finish
SetLocal
Set S=C:\Windows
For /R %S /D %E in (*) Do ( Echo %E )
Z:\SampleC.bat [6] Usage : FOR [/A:[[-][+]rhsdaecjot] /D /F ["options"] /H /I"text" /L /R [p
Z:\SampleC.bat [6] Usage : FOR [/A:[[-][+]rhsdaecjot] /D /F ["options"] /H /I"text" /L /R [p
Z:\SampleC.bat [6] Usage : FOR [/A:[[-][+]rhsdaecjot] /D /F ["options"] /H /I"text" /L /R [p

repeated idefinitely.

Is this an implication that the "range" parameter can not be a variable? What am I missing here?

TCC 9.02.152 Windows Vista [Version 6.0.6001]
 
Is this an implication that the "range" parameter can not be a variable?
No, just that your syntax is wrong in some way.

What am I missing here?
Quotes around the value of the R switch (as per the help - Warning: if the directory name includes special characters, including "%" to indicate an environment variable, it must be enclosed in double quotes (").), so the following should work:

For /R "%S" /D %E in (*) Do (
 

Similar threads

Back
Top