0

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
  • 16,009
  • 9
  • 78
  • 91
Sithu
  • 4,504
  • 9
  • 60
  • 107

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
  • 19,124
  • 5
  • 38
  • 71
1

There is no such thing in batch scripts.

(gotos excluded...)

Martin G
  • 16,009
  • 9
  • 78
  • 91
1

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
  • 61,954
  • 12
  • 66
  • 99
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
  • 39
  • 1
  • 5
  • 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://docs.microsoft.com/en-us/windows-server/administration/windows-commands/break – superbox May 05 '22 at 10:39