Package how to end the for loop

for testing purposes, I need a recursive directory with some files that reaches the maximum path length.

The script used to create consists of only two for-loops loops:

for /L %%a in (1 1 255) do @( mkdir %%a && cd %%a && for /L %%b in (1 1 %random%) do @( echo %%b >> %%a.txt ) ) 

Now I would like to insert this Script as part of another script, since there is still more to do, but I cannot add any other commands around it or refuse to work. I use it under Windows Vista if it is useful to you.

It does not work if I write "@ECHO OFF " in the first line, nor with " echo done " in the last line.

output on the command line:

 X:\Scripte>recursive.cmd OFFfor /L %a in (1 1 255) do @( mkdir %a The system cannot find the path specified. 

EDIT: There seems to be a problem with layer 8, the problem seems to be in the shell used, if bare cmd.exe is used, it works, it does not work with the visual studio 2008 command shell, as mentioned above.

Anyway, thanks.

+4
source share
2 answers

I don’t think you need “@ before paranas” or “& &” inside the body of the loop; parens takes care of processing multiple statements in a for loop.

The following works for me:

 @echo OFF for /L %%a in (1 1 255) do ( @echo a = %%a mkdir %%a cd %%a for /L %%b in (1 1 %random%) do ( echo %%b >> %%a.txt ) ) @echo done 
+1
source

I don’t understand how to add a small comment below the answer, so I’ll just do it here.

The @ sign in front of an open bracket is only necessary if the echo is not turned off. In this case, what happens without the @ sign is that every command in the FOR loop will be an echo.

And yes, the reason for the && need is that the text editor puts everything on one line. But no one posted the solution. Just copy and paste into Notepad, and then split the lines as needed.

+2
source

All Articles