Category : Batch File Utilities - mostly for DOS
Archive   : DOSVAR.ZIP
Filename : DV_DEMO.BAT

 
Output of file : DV_DEMO.BAT contained in archive : DOSVAR.ZIP
@ECHO OFF

IF NOT (%1) == (X) START

CLS
ECHO First, we will display the built-in help...
ECHO ÿ
ECHO The command to do this is: DOSVAR /?
SHOWTEXT CQ
IF ERRORLEVEL 2 GOTO QUIT


DOSVAR /?
SHOWTEXT CQ
IF ERRORLEVEL 2 GOTO QUIT

CLS
ECHO -----------------------------------------------------------------------
ECHO EXAMPLE # 1 - Strip Leading Zeros, Justify Right, Pad with $ character
ECHO -----------------------------------------------------------------------
ECHO ÿ
ECHO ON
DOSVAR /nMYVAR /v0000000000456 /zY /jR /O6 /c$
@ECHO OFF
CALL SETVAR
ECHO ÿ
ECHO The expected result is: [$$$456]
ECHO The actual result is: [%MYVAR%]
SHOWTEXT CQ
IF ERRORLEVEL 2 GOTO QUIT

CLS
ECHO -----------------------------------------------------------------------
ECHO EXAMPLE # 2 - Substring: Take the 7 characters on the right
ECHO -----------------------------------------------------------------------
ECHO ÿ
ECHO ON
DOSVAR /nMYVAR /v0000000000456 /sR /i7
@ECHO OFF
CALL SETVAR
ECHO ÿ
ECHO The expected result is: [0000456]
ECHO The actual result is: [%MYVAR%]
SHOWTEXT CQ
IF ERRORLEVEL 2 GOTO QUIT

CLS
ECHO -----------------------------------------------------------------------
ECHO EXAMPLE # 3 - Substring (input string is shorter than requirement)
ECHO -----------------------------------------------------------------------
ECHO ÿ
ECHO ON
DOSVAR /nMYVAR /vXX456 /sR /i7
@ECHO OFF
CALL SETVAR
ECHO ÿ
ECHO The expected result is: [XX456]
ECHO The actual result is: [%MYVAR%]
SHOWTEXT CQ
IF ERRORLEVEL 2 GOTO QUIT

CLS
ECHO -----------------------------------------------------------------------
ECHO EXAMPLE # 4 - Take 3 chars on left, Justify right, pad with X's
ECHO -----------------------------------------------------------------------
ECHO ÿ
ECHO ON
DOSVAR /nMYVAR /v123456789 /sL /i3 /jR /o4 /cX
@ECHO OFF
CALL SETVAR
ECHO ÿ
ECHO The expected result is: [X123]
ECHO The actual result is: [%MYVAR%]
SHOWTEXT CQ
IF ERRORLEVEL 2 GOTO QUIT

CLS
ECHO -----------------------------------------------------------------------
ECHO EXAMPLE # 5 - Justify right, using space (default) padding char
ECHO -----------------------------------------------------------------------
ECHO ÿ
ECHO ON
DOSVAR /nMYVAR /v0000000000456 /jR /o6 /zY
@ECHO OFF
CALL SETVAR
ECHO ÿ
ECHO The expected result is: [ 456]
ECHO The actual result is: [%MYVAR%]

ECHO ÿ
PAUSE
SET MYVAR=

:QUIT
START


  3 Responses to “Category : Batch File Utilities - mostly for DOS
Archive   : DOSVAR.ZIP
Filename : DV_DEMO.BAT

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/