Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

single line for statement: %%i 'unexpected at this time'

Tags:

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

Results in

%%i was unexpected at this time

Why?

like image 676
blippy Avatar asked Jan 17 '12 16:01

blippy


People also ask

What does %% I mean?

%%i is simply the loop variable. This is explained in the documentation for the for command, which you can get by typing for /? at the command prompt.

Was unexpected at this time batch file?

If you are getting this error on your IF statement check if used or not your double equals to compare your variable. Eg. This throws "=1 was unexpected at this time." To correct this add another equals sign.

How do I comment in a batch file?

A batch file can be commented using either two colons :: or a REM command. The main difference is that the lines commented out using the REM command will be displayed during execution of the batch file (can be avoided by setting @echo off ) while the lines commented out using :: , won't be printed.

Does the syntax of the command is incorrect?

In the Windows command line, when trying to copy, move, or rename a file or directory with a space, you may get the "The syntax of the command is incorrect" error message. This error message is generated when the Windows command line does not understand the syntax of the command because it is not formatted properly.


1 Answers

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.

like image 123
dbenham Avatar answered Oct 05 '22 09:10

dbenham