1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

(Somewhat unbelievable) Do While Behavior/Question

Discussion in 'Support' started by mathewsdw@sbcglobal.net, Dec 9, 2008.

  1. 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]
     
  2. Steve Pitts

    Joined:
    Jul 7, 2008
    Messages:
    158
    Likes Received:
    0
    No, just that your syntax is wrong in some way.

    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 (
     

Share This Page