Search code examples
windowsbatch-fileerror-handlingarguments

"was unexpected at this time."


I'm running this command on a batch file:

for %I in (*.txt *.doc) do copy %I c:\test2

...and it keeps returning:

I was unexpected at this time.

What is the cause of this error?


Solution

  • If you're running within a batch/cmd file, you need to double the % markers:

    for %%i in (*.txt *.doc) do copy %%i c:\test2
    

    The single % variant only works from the command line.