Question

for testing purposes i need an recursive directory with some files, that comes to maximum path-length.

The Script used for the creation consists only of two for-loops, as followed:

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 embed this script as part of another script, since more is to be done, but I can not add any other commands around it or it refuses working. I use this under windows vista, if this is useful to you.

Nor it works if i write "@ECHO OFF" in first line, neither with "echo done" on the last line.

output on commandline is:

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

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

anyway, thank you.

Was it helpful?

Solution

I don't think you need the '@'s in front of the parens or the '&&' within the for loop body; the parens take care of handling multiple statements in the 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

OTHER TIPS

I don't understand how to add a little comment below an answer, so I'll just do it here.

The @ sign in front of the open parenthesis is needed only if echo is not already off. In that case, what would happen without the @ sign is that every command in the FOR loop would be echoed.

And, yes, the reason for needing && is that the text editor is putting it all on one line. But no one posted a solution. Just copy and paste into Notepad, and then separate the lines as necessary.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top