single line for statement: %%i 'unexpected at

2019-03-12 11:37发布

for /r %%i in (*) do (echo %%i)

Results in

%%i was unexpected at this time

Why?

标签: for-loop cmd
2条回答
ら.Afraid
2楼-- · 2019-03-12 12:34

Syntax:

FOR /R [[drive:]path] %%parameter IN (set) DO command

Need the path before %%i... which is why it's Unexpected

If you want to do * for current directory, just use ".\" for the path

for /r ".\" %%i in (*) do (echo %%i)
查看更多
虎瘦雄心在
3楼-- · 2019-03-12 12:38

You must be trying to run the command from the command line and not from within a batch file. Use a single % instead of two when running from the command line.

for /r %i in (*) do (echo %i)

Type HELP FOR from the command line and read the 3rd paragraph.

查看更多
登录 后发表回答