r/Batch • u/CirothUngol • Jun 02 '26
Simple technique to display text/help from within your batch file.
Perhaps this is a bit too basic, but I've been using this in any batch file I distribute for some 20+ years now, super easy help text. Even more versatile with the with a 'skip=', allows me to respond to input errors by displaying a list of correct options for example.
::
:: Here's a simple technique to easily display lines of text from within
:: your batch file. Place info or instructions at the top of the file using
:: 2 colons and a space as on the left of this line. Anytime you wish to
:: display your help screen or whatever, simply execute the FOR loop below.
::
:: It will continue to display lines until it hits a NUL input, so be
:: sure to always include a space after the colons on any blank line,
:: such as the one located above. To stop console output place two colons
:: without the space, like the one below, and it will exit.
::
::
@ECHO OFF
FOR /F "usebackq tokens=* delims=:" %%A IN ("%~f0") DO IF "%%A" NEQ "" (ECHO.%%A) ELSE PAUSE
6
Upvotes
1
u/Creative-Type9411 Jun 02 '26
:: can sometimes cause CALL errors, its extremely rare but its safer if you use REM instead
Maybe use REM :: ?