1

Is there any syntax for multi-line code block comment in Windows batch script? I know REM and :: for line-by-line comment, but it is not efficient to comment a code block.

I'm looking for the block comment style like something below in PHP:

/*
This is multi-lines
block comment
*/
Martin G
  • 17,357
  • 9
  • 82
  • 98
Sithu
  • 4,752
  • 9
  • 64
  • 110

4 Answers4

2

I think, this can serve the purpose

goto:skip1
echo This line should not get executed
format c: & echo nor this line
:skip1
anishsane
  • 20,270
  • 5
  • 40
  • 73
2

You may use this trick that looks better...

@echo off
setlocal

set comment=goto endcomment

echo This line is executed

%comment%
echo These lines
echo are commented out...
:endcomment

echo The next line to execute

%comment%
You may place here
  %$#"#% anything you want.... &!>|<()
:endcomment

echo End of example
Aacini
  • 65,180
  • 12
  • 72
  • 108
1

There is no such thing in batch scripts.

(gotos excluded...)

Martin G
  • 17,357
  • 9
  • 82
  • 98
0

Multiline comment without that gotos, rems and ::

@break || (
 1 line
 2 line
 3 line
 4 line
 5 line
 ...
)

EDIT: As the previous example is not working, you can create a macro

set "[:=goto :]%%"
set "[=rem/||(" & set "]=)"
%[:%
  multiline
  comment
%:]%

(Not works in the for loop)

superbox
  • 53
  • 1
  • 7
  • How is this supposed to work? What does @break normally do? (Also, this syntax didn't work for me in a batch file. It still executed the excluded lines) – gamingexpert13 May 04 '22 at 23:16
  • 1
    @gamingexpert13 Sets or clears extended CTRL+C checking on MS-DOS systems. If used without parameters, break displays the existing setting value. If command extensions are enabled and running on the Windows platform, inserting the break command into a batch file enters a hard-coded breakpoint if being debugged by a debugger. Details: https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/break – superbox May 05 '22 at 10:39