Posted On 2007-04-24 by FortyPoundHead
Keywords: Command Reference
Tags: Windows Commandline Windows
Views: 1501

In a batch file
REM signifies a comment or REMARK
adding :: at the start of a line has a similar effect

For example:

:: First comment
REM Second comment
Although you can use rem without a comment to add vertical spacing to a batch file, you can also use blank lines. The blank lines are ignored when processing the batch program.

The double-colon is not documented as a comment command, it is a special case of a CALL label that acts like a comment. The pro''s and cons of each method are listed below.

There are problems using a :: comment within an IF or FOR code bracket
@echo off
FOR /L %%i IN (1,1,10) Do (
Echo before comment
:: Some comment
Echo after comment

The above will return the error :: was unexpected at this time.

In the script below the DIR command will set an %errorlevel%=2 if the file is not found, but the REM command is then executed successfully and resets %errorlevel%=0
If you use :: for the comment the errorlevel stays at 2.

DIR nonexistentfile.txt
REM some comment
ECHO %errorlevel%

The problem above was fixed* in Win XP and later service packs of NT 4.

Finally in Windows 2000 and XP a comment like
REM %~ will be interpreted giving the error:
The following usage of the path operator in batch-parameter substitution is invalid: %~

The bottom line on this is that you must test your comments to be sure they will be ignored as you expect.

Registry Comments

Within a registry file comments can be preceded by "; "
; Turn the NUMLOCK on at login
[HKEY_CURRENT_USER\Control Panel\Keyboard]

FTP Comments

There is no valid comment character for FTP but you can cheat by escaping to the shell and running REM

C:\WORK>type ftpscript
!REM This is a remark

C:\WORK>ftp -s:ftpscript
ftp> !REM This is a remark
ftp> bye


* The errorlevels set by DIR are different under Windows NT 4 and XP

About the Author

has posted a total of 1974 articles.

Comments On This Post

No comments on this post yet!

Do you have a thought relating to this post? You can post your comment here. If you have an unrelated question, you can use the Q&A section to ask it.

Or you can drop a note to the administrators if you're not sure where you should post.

Your IP address is:

Before you can post, you need to prove you are human. If you log in, this test goes away.

Code Links