
Also, code blocks are a pitfall for this trick as commands grouped by parentheses are interpreted as a single command line by the batch interpreter, which then obviously invalidates our ‘fake’ label as just mentioned above – your comment most likely won’t be sitting at the start of the concatenated command line!įinally you can write multiple lines of comments (or comment blocks) by making use of the ability to jump over your lines of comment using the GOTO statement.

However, this trick does not allow you to start a comment mid line as labels always start at the first non-whitespace character in a command line. This trick has the advantage of not slowing down the interpreter because it doesn’t have to stop to interpret the command statement like it has to for a REM statement – it simply jumps to the next line of the file without having to first reread the whole file again! :: Comment - This bat-file moves all files The first colon tells the batch interpreter that the following text is a label, while the second colon invalidates the label status but then forces the interpreter to still treat the line as a label anyway. The second way of commenting out a line in a batch file is by utilizing a clever trick that in essence has you converting your comment line into a label by prefixing it with a double colon (::). (It’s echo off to avoid printing further commands the is to avoid printing that command prior to the echo setting taking effect.) If however you want to avoid printing a command, including the REM statement, prefix it with or, to apply that setting throughout the program, run off. Since REM commands don’t do anything, it’s safe to print them without any side effects. REM Comment - This bat-file moves all filesĪt this point it might be useful to remind yourself that by default the batch interpreter will print out each command before it is processed. the batch file is read, the command is executed, and then the batch file is reread in order to execute the next command, rinse and repeat until the end of the file, REM statements do in essence slow down the execution of a batch file – though taking into account today’s processing power, this slowdown is negligible (unless of course your batch file is SUPER long!). Of course, because the way in which batch files are processed by COMMAND.COM and CMD.EXE, i.e. Any line in your batch file that starts with REM (which stands for REMark) is completely ignored by the batch interpreter.



The first, most recognised way (standards-compliant, documented statement) is by making use of the REM statement. As a reminder to myself so that I don’t have to Google it each and every time I need to work on a Windows Server (in other words, very seldom), there are three ways of adding comments into batch files (.bat) in Windows.
