Redirect output of command in for loop of batch script

TripShock picture TripShock · Jun 14, 2013 · Viewed 11.4k times · Source
...
for /F %%F in ('dir /B %* 2> nul') do (
...

What I'm attempting to do here is discard the err output of the command (and loop over the stdout output). However, it complains:

2> was unexpected at this time.

Is this some way to achieve this?

Answer

RGuggisberg picture RGuggisberg · Jun 14, 2013

in this case you need to escape the > like this

for /F %%F in ('dir /B %* 2^> nul') do (