Redirect output of command in for loop of batch script
in this case you need to escape the > like this
for /F %%F in ('dir /B %* 2^> nul') do (
in this case you need to escape the > like this
for /F %%F in ('dir /B %* 2^> nul') do (