Comment In Windows Batch File Average ratng: 5,0/5 9133 votes

I've been writing some batch files, and I ran into, which has been quite informative. One thing it showed me was that lines can be commented not just with REM, but also with:. It says:Comments in batch code can be made by using a double-colon, this is better than using the REM command because labels are processed before redirection symbols.:: causes no problems but rem produces errors.Why then, do most guides and examples I see use the REM command? Does:: work on all versions of Windows? Tl;dr: REM is the documented and supported way to embed comments in batch files.:: is essentially a blank label that can never be jumped to, whereas REM is an actual command that just does nothing. In neither case (at least on Windows 7) does the presence of redirection operators cause a problem.However,:: is known to misbehave in blocks under certain circumstances, being parsed not as a label but as some sort of drive letter.

I'm a little fuzzy on where exactly but that alone is enough to make me use REM exclusively. @mosh is right. For instance,%VAR% variables are expanded. Suppose you have (wrongly) set TARGET=C:Program Files (x86)'foo.exe', and inside a DO(.) expression you have:: echo%TARGET% you will get an error because the (x86) gets expanded before the whole expression gets evaluated, leading to an invalid DO(.) expression and very inexplicable errors (in this case 'Microsoft was unexpected at this time'). You don't even need or in your expression. A:: is not a real comment, REM is, though.–Sep 28 '17 at 1:06. Comments with REMA REM can remark a complete line, also a multiline caret at the line end, if it's not the end of the first token.

Comment In Windows Batch File Command Line Arguments

REM This is a comment, the caret is ignored^echo This line is printedREM Thisisacommentthecaretappendsthenextline^echo This line is part of the remarkREM followed by some characters.:/= works a bit different, it doesn't comment an ampersand, so you can use it as inline comment. Echo First & REM. This is a comment & echo secondBut to avoid problems with existing files like REM, REM.bat or REM.bat only a modified variant should be used. Another alternative is to express the comment as a variable expansion that always expands to nothing.Variable names cannot contain =, except for undocumented dynamic variables like%=ExitCode% and%=C:%. No variable name can ever contain an = after the 1st position. So I sometimes use the following to include comments within a parenthesized block:::This comment hack is not always safe within parentheses.(%= This comment hack is always safe, even within parentheses =%)It is also a good method for incorporating in-line comments dir junk nul 2&1 &&%= If found =% echo found %= else =% echo not foundThe leading = is not necessary, but I like if for the symmetry.There are two restrictions:1) the comment cannot contain%2) the comment cannot contain. After I realized that I could use label:: to make comments and comment out code REM just looked plain ugly to me.

Rename Multiple Files using Windows Explorer. Go to the folder having the files you want to rename. Select a file then either use Tab button to select other files or you can use Shift key to select batch of files you wanted to rename. If you are renaming all the files in the folder, press Ctrl + A key to select all the files. A batch file is a kind of script file in DOS, OS/2 and Windows. It consists of a series of commands to be executed by the command line interpreter, stored in a plain text file. Source: Wikipedia. How to Delete a File in Microsoft Windows Using Batch Files. This wikiHow teaches you how to delete a file on your Windows computer by using a Batch file. Batch files are small files which can run commands via your computer's built-in.

File

As has been mentioned the double-colon can cause problems when used inside blocked code, but I've discovered a work-around by alternating between the labels:: and: space:: This, of course, does:: not cause errors.(:: But: neither:: does: this.)It's not ugly like REM, and actually adds a little style to your code.So outside of code blocks I use:: and inside them I alternate between:: and.By the way, for large hunks of comments, like in the header of your batch file, you can avoid special commands and characters completely by simply gotoing over your comments. This let's you use any method or style of markup you want, despite that fact that if CMD ever actually tried to processes those lines it'd throw a hissy.

File

@echo offgoto:TopOfCodeCOOLCODE.BATUseage:COOLCODE /? /a/c:##abc INPUTFILE OUTPUTFILE Switches:/? - This menu/a - Some option/c:## - Where ## is which line number to begin the processing at.:a - Some optional method of processing:b - A third option for processing:c - A forth optionINPUTFILE - The file to process.OUTPUTFILE - Store results here.Notes:Bla bla bla.:TopOfCodeCODE.Use what ever notation you wish.'

s, @'s etc. Good question. I've been looking for this functionality for long too.after several tests and tricks it seem the better solution is the more obvious one.- best way I found to do it, preventing parser integrity fail, is reusing REM: echo this will show until the next REM &REM this will not showyou can also use multiline with the 'NULL LABEL' trick.(dont forget the ^ at the end of the line for continuity)::(^this is a multiline^comment. Inside a null label!^dont forget the ^caret at the end-of-line^to assure continuity of text^). James K, I'm sorry I was wrong in a fair portion of what I said. The test I did was the following: @ECHO OFF(:: But: neither:: does: this:: also.)This meets your description of alternating but fails with a ') was unexpected at this time.' Error message.I did some farther testing today and found that alternating isn't the key but it appears the key is having an even number of lines, not having any two lines in a row starting with double colons (::) and not ending in double colons.

Consider the following: @ECHO OFF(: But: neither: does: this: cause: problems.)This works!But also consider this: @ECHO OFF(: Test1: Test2: Test3: Test4: Test5ECHO.)The rule of having an even number of comments doesn't seems to apply when ending in a command.Unfortunately this is just squirrelly enough that I'm not sure I want to use it.Really, the best solution, and the safest that I can think of, is if a program like Notepad would read REM as double colons and then would write double colons back as REM statements when the file is saved. But I'm not aware of such a program and I'm not aware of any plugins for Notepad that does that either.