Menu From the News
Page 1
Index
Index Page 2 | Trash


     Xy.bat
     Longest.bat
     Delimit8.bat | (better see my new version)
     Set and test an Errorlevel parameter
 --> GO.BAT, Batch Search the WEB
     Debug~it.bat, (a toolbox for Mr Bug)
     Write HTML from Batch, (detecting RAMdrive and bennyLevels)
     ECHO ON/OFF in another COMMAND.COM session,
         (if errorlevel bennyLevel if not errorlevel bennyLevel)
     Reverse order of lines
     Calculating and converting or use this method...


     Examples from a News Group [MSDOS.BATCH] Jan 23, 01

     The following batch program is solid as a rock i.e.
     it should be okay to use it as a templete for other
     solutions. It don't hanging in endless loops and no
     temporary files or other files are written and when
     the batch is over, then all variables, which I used
     is completely cleaned up.

     The batch file contains information about:

     1.: How to convert an input from lower to uppercase
         or upper to lowercase.

     2.: How to count a number of elements in a variable
         %v% using choice:

         echo.. | choice /c'%v%..COUNT: Set D=Number of elements >nul
         for %%v in (1 2 3 4 5 6 7 8) do if errorlevel }%%v set D=%%v
         echo Number of elements are: (%D%)

         etc...


: XY BAT by Benny Pedersen, [http://2dos.homepage.dk]
::
@if not %1'==' for %%v in (set goto:Loop ) do %%v D=X
@echo off
     for %%v in (i L_1 L_2 ) do set %%v=
     echo.Input the LIST, then press Esc to continue:
:Ask (      /n/c123456 SIX characters of ASCII 27 :-)
     choice /n/cabcdefghijklmnopqrstuvwxyz%L_1%
     rem Two long lines (113 char:)
     for %%v in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do if
errorlevel _%%v set L_1=%L_1% %%v %I%
     for %%v in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do if
errorlevel /%%v set L_2=%L_2% %%v %I%
     for %%v in (cls if:errorlevel) do %%v 7 goto ask
     for %%v in (if:not goto:EOF) do %%v %L_1%'==' %0 %L_1%+%L_2%+
:Loop
     set %D%%I%=%1
     for %%v in (hif e) do s%%vt I=%I%I
     if not %1==+ if not "%I%"=="IIIIIIII" goto: Loop
:Shift
     if not %1==+ for %%v in (call goto) do %%v shift
     echo.. | choice /cI%I%..COUNT: Set D=Number of elements >nul
     if %D%==Y for %%v in (1 2 3 4 5 6 7 8) do if errorlevel }%%v set D=%%v
     for %%v in (shift set:I set:L_1 set:L_2) do %%v=
     if %D%==X for %%v in (set goto:Loop:) do %%v D=Y
     echo.
     echo  [Number of elements] = [%D%]
     echo  [%X%%Xi%%Xii%%Xiii%%Xiiii%%Xiiiii%%Xiiiiii%%Xiiiiiii%]
     echo  [%Y%%Yi%%Yii%%Yiii%%Yiiii%%Yiiiii%%Yiiiiii%%Yiiiiiii%]
     echo  [%Y%%Xi%%Xii%%Xiii%%Xiiii%%Xiiiii%%Xiiiiii%%Xiiiiiii%]
     echo   if 8 characters, then 256 combinations/permutations:
     echo   rem: _[SNIPED]_

:End -- One long line (119 char:)
     for %%v in (D X Y Xi Yi Xii Yii Xiii Yiii Xiiii Yiiii Xiiiii Yiiiii Xii
iiii Yiiiiii Xiiiiiii Yiiiiiii) do set %%v=
:EOF


     Which is longest.  :-) :--) :---)

     Note: if N2 consist of 10 or more
           than 10 characters, then N1
           mustn't be increased to 10,
     i.e.: if two variables content of
     digits are as N2 >=1.000.000.000,
     then N1 must be < 10.000.000.000.

: Longest bat
::
@echo off
     set N1=123
     set N2=45962200212200104575503646

     echo..| choice /c'%N1%.>nul
     for %%v in (0 1 2 3 4 5 6 7 8 9 :) do if errorlevel }%%v set Len_N1=%%v
     echo..| choice /c'%N2%.>nul
     for %%v in (0 1 2 3 4 5 6 7 8 9 :) do if errorlevel }%%v set Len_N2=%%v

     if not errorlevel }%Len_N1% set Result= n1 is longest
         if errorlevel }%Len_N1% set Result= n2 is longest
         if }%Len_N2%==}%Len_N1% set Result= *Same length*

     echo Result:  [%Result% ]
     :-) 


     From the News [MSDOS.BATCH] March 1, 2001.

     Delimit8.bat

     Normal usage:
         delimit8.bat number
         Returns all digits of the number.

     Examples:
         delimit8 01437
         Returns D= 0 1 4 3 7

     Wrong usage i.e. other characters than numbers:
         delimit8 bc45px3
         Returns D= 4 5 3

         delimit8 125,34
         Returns D= 1 2 5

     Test.bat: (tested on DOS6.22 (USA version) and Win98 (DK version))
         @echo off
         call delimit8 33
         delimit8

     Tips:
         Reverse the order of %D% and %%D (line number 3), "D=%%D %D%"
         instead of "D=%D% %%D" and the output will be reversed.

     Notes:
         If an input consist of more than 8 characters, then it
         truncates the input of the first 8 characters.

@if not %B%'==delimit8' goto INPUT
:OUTPUT
 for %%D in (0 1 2 3 4 5 6 7 8 9) do if 3%%D==%2 set D=%D% %%D
 if not %4'==' for %%D in (shift goto:OUTPUT) do %%D
 echo %3, D=%D%
 for %%D in (D B cmdline) do set %%D=
 for %%D in (del pause cls goto:EOF) do %%D input$.*
:INPUT
 @if %1'==' for %%D in (echo.Cancellation goto:EOF) do %%D
 rem>input$.scr
 for %%D in (L102 W F100LFF''1A L W102 Q) do echo %%D>> input$.scr
 echo %0 >input$.bat
 debug    input$.bat<input$.scr> nul
 copy     input$.bat + nul > nul
 echo ; | choice /c'%1; see next line: set B= "Length(input)" >nul
 for %%D in (1 2 3 4 5 6 7 8) do if errorlevel }%%D set B=%%D
 echo D100L%B%>      input$.scr
 echo Q>>            input$.scr
 echo %1> input$.tmp
 debug    input$.tmp<input$.scr | find ":" >>input$.bat
 for %%D in (set input$) do %%D B=delimit8
:EOF


    From the News [MSDOS.BATCH] March 2, 2001.

    Usage: %0 number.  %0 does 3 things:

p1. Set errorlevel equivalent to the specified number
p2. Performs a test: What is the errorlevel?
p3. Displays the errorlevel (found in the above test)

 @echo off
 @echo %1( | choice /c1234567890(1'th digit num?)>nul
 if errorlevel 11 for %%@ in (echo goto) do %%@ Usage
 if exist ERRL.C* for %%@ in (ERRL goto:EL) do %%@ %1
 @echo %0? | find /i ".bat?" >nul
 set @=%0
 if errorlevel 1 set @=%0.bat
 if not exist %@% for %%@ in (echo goto) do %%@ Usage
 find " ""Public Domain by Bruce Desmond " < %@%> nul
 if errorlevel 1 for %%@ in (echo. goto) do %%@ Usage
 find /v "@" <%@%> ERRL.SCR
 @for %%@ in (rCX 10E w q) do echo %%@>> ERRL.SCR
 @echo.>ERRL.COM
 @debug ERRL.COM < ERRL.SCR > nul
 @ERRL.COM %1
 for %%@ in (SCR COM) do del ERRL.%%@
:EL @
 :: @  About prefix of zero(s):
 :: @  If you delete the "@SET E=" and "IF ERRORLEVEL 10 ",
 :: @  then you must substitute "(  1 2 )" with "(0 1 2 )".
 @SET E=
 SET @=( 0 1 2 3 4 5 6 7 8 9 )
 FOR %%@ IN (  1 2 ) DO IF ERRORLEVEL %%@00 SET E=%%@
 IF ERRORLEVEL 200 SET @=( 0 1 2 3 4 5 )
 IF ERRORLEVEL 10 FOR %%@ IN %@% DO IF ERRORLEVEL %E%%%@0 SET E=%E%%%@
 IF NOT ERRORLEVEL 250 SET @= ( 0 1 2 3 4 5 6 7 8 9 )
 FOR %%@ IN %@% DO IF ERRORLEVEL %E%%%@ SET E= %E%%%@
 @ECHO Current status of the ERRORLEVEL parameter:%E%
 @for %%@ in (   set pause cls goto:END   ) do %%@ E=
:Usage @
 @echo. %0 number
 for %%@ in ( echo. echo. pause cls goto:END ) do %%@
e100 FC BE 81 0 AC "<"D "t/< t"F7 "<"9 "t" F3 "<0r#<9w"1F BB A 0 "2"E4
e11E "7"86 C7 F6 E3 "p" 13 2 F8 "r"F AC "<0r"4 "<9v"EA 86 C7 B4 "L" CD
e137 "!"BA "C"1 B4 9 CD "!"B0 0 EB F1 D A "Seterrl.com  v0.11  02/21/"
e15F "93  Set Dos errorlevel to specified nnn"D A "  Released to the "
e19A "Public Domain by Bruce Desmond (1:203/555.9)"D A D A " Usage: S"
e1D3 "eterrl ###   where ### is a decimal number from 0 to 255"D A "$"
:END @
 set @=


    From the News [MSDOS.BATCH] March 3, 2001.

    GO interesting DOS Laura
    I tried the above syntax for testing the below GO.BAT file.

    That Google search machine is simply the best and the fastest
    search machine I ever have seen!

    Laura, I have modified your file (172 bytes in 6 lines), hope it's Ok.

@ECHO OFF
SET _=%1
:_
IF NOT _%2==_ FOR %%_ IN (SET SHIFT GOTO) DO %%_ _=%_%+%2
START http://www.google.com/search?q=%_%&btnG=Google+Search&hl=en&lr=&safe=off
SET _=

    Hint:  For additional information about GO.BAT by Gary L. Smith,
           see the trash section or find/visit my freeware Homepage.


    A toolbox for Mr / Miss Bug. (Updated and removed April 29, 2001).
    The following is the previous/old version:

    @echo off %" Usage of Debug~it: Open it or drag and drop a file "%
    if not exist %1 call goto N        > %temp%.\~tmp.scr
    for %%v in ( .rcx . .q ) do echo%%v>>%temp%.\~tmp.scr
    debug  %1  < %temp%.\~tmp.scr      > %temp%.\~tmp.bat
    dir /b %1
    echo E 0100 20 20" set CX" 3D      > %temp%.\~tmp.scr
    for %%v in (rCX 10 w q) do echo %%v>>%temp%.\~tmp.scr
    debug        %temp%.\~tmp.bat      < %temp%.\~tmp.scr > nul
    call         %temp%.\~tmp.bat
    :N
    echo.%1
    echo.   ÿÿÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
    echo.   1:³ EE0"0123456789ABCDEF"                  ³
    echo.   2:³ FF0L10 0 1 2 3 4 5 6 7 8 9 A B C D E F ³
    if not %1'==' echo.   3:³ DE0 L20                                ³
    if not %1'==' echo.   4:³ D100L%CX%                              ³
    if     %1'==' echo.   3:³ F100LFF0''23                           ³
    if     %1'==' echo.   4:³ DE0 L140                               ³
    echo.     ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄ¿
    echo.                                              ³ ÉÍÍÍËÍÍÍ» ³
    echo.     Copy and paste the above window or press ³ º N ºRCXº ³
    echo.     q to quit Debug.                         ³ ÌÍÍÍÎÍÍ͹ ³
    echo.                                              ³ º W º Q º ³
    echo.     Benny Pedersen, http://2dos.homepage.dk/ ³ ÈÍÍÍÊÍÍͼ ³
    echo.     PS:  try also "DE0", "DE0LA0" or "D100". ÀÄÄÄÄÄÄÄÄÄÄÄÙ
    set CX=
    erase %temp%.\~tmp.???
    debug %1
    cls


 Write HTML from Batch.

 I toke a visit on the Net to see what they was talking about.
 I found this discussion.

 If you don't wanted to read the fun stuff, then you may click
 on the following link:  Write HTML from Batch.

 Todd Vargo, Outsider, Frank-Peter Schultze and other...

 Todd Vargo wrote:
    I like this code instead.
    ::Autoexec.bat for CDROM boot
      a:\findramd.exe
      for %%? in (C D E ... X Y Z) do if errorlevel H%%? set RamDrive=%%?

 Outsider wrote:  What is the H for?

 Frank-Peter Schultze (schrieb im Newsbeitrag)
    H is used as an offset.
    Never heard about "BennyLevel ERRORLEVEL Checking"?
    ;-)

 Outsider:  Yes, I have. I just hadn't got a proper grasp on it.

 Benny thinks:
    AHA, they used a discovery of mine to create a program,  :-)
    Now let's teasing and have some fun!

 Benny wrote:
    Outsider, now you may have grasped it so, let's make some more creative
    BennyLevels.
    GOTO insider

    Regards Benny,
    BTW. My site was mirrored yesterday on Warsaw university :-)
    www.wsisiz.edu.pl/~bse26236/

    :Insider
    FINDRAMD.EXE
    FOR %%d in (C D E F G H I J K L ) do IF errorlevel H%%d set ramdrive=%%d
    Snip...
                 (7 alternative solutions to the above H%%d)
        %(1)%                                    ppppppH%%d
        %(2)%                                         L0%%d
        %(3)%                      ::_Outsider_::ppppF00%%d
        %(4. Symmetry:   )%                   d%%0pp?pp0%%d
        %(5. ASCII ART   )%                   d%%0pp_pp0%%d
        %(6. To easy :-b )%                   d%%0ppOpp0%%d
        %(7. Total symmetrically )%   b%%00?0000?0000?00%%d

 Outsider wrote:
    They all worked except number 7, but I don't know how.?

 [End of fun].

 Benny wrote:
    At once, immediately after I posted this, I saw that my
    post reader (Outlook Express 5) converted the character
    of ASCII value 134 to question marks. I don't wanted to
    reply my own mails so, I waited to see if another would
    reply. :-)  Benny, http://users.cybercity.dk/~bse26236/

    The following is based on number 7 above.

    Write HTML from Batch

    ::DontWrap.bat 41 lines and 2327 byte, (it's NOT the best solution.)
      @echo off
      CD %temp%.
      ECHO @prompt $LFONT color="blue" face="andale mono"$G  > (FONT.bat
      ECHO @prompt $L/FONT$G                                 > FONT).bat
      ECHO @prompt $LBR$G $L!-- (This is a line break) --$G  > BR.bat
      ECHO @prompt $LTEXTarea rows="7" cols="50"$G           > (TEXT.bat
      ECHO @prompt $L/TEXTarea$G $LBR$G $LBR$G               > TEXT).bat
      %COMSPEC% /C (TEXT.bat                                 > paste.htm
      echo::Copy & paste the following batch to Notepad, (or>> paste.htm
      echo::a similar ASCII editor). You can always use your>> paste.htm
      echo::MS-DOS Editor BUT later! The reson for not using>> paste.htm
      echo::this editor is that a paste operation can fails!>> paste.htm
      %COMSPEC% /C TEXT).bat                                >> paste.htm
      echo @ECHO off                                        >> paste.htm
      %COMSPEC% /C BR.bat                                   >> paste.htm
      echo SET ramdrive=                                    >> paste.htm
      %COMSPEC% /C BR.bat                                   >> paste.htm
      echo if exist %%windir%%\command\FINDRAMD.EXE FINDRAMD>> paste.htm
      %COMSPEC% /C BR.bat                                   >> paste.htm
      echo if not exist %%windir%%\command\FINDRAMD.EXE     >> paste.htm
      echo %%windir%%\command\EBD\FINDRAMD                  >> paste.htm
      %COMSPEC% /C BR.bat                                   >> paste.htm
      echo  FOR %%%%d in (C D E F G H I J K L M N           >> paste.htm
      echo   O P Q R S T U V W X Y Z) do    IF errorlevel   >> paste.htm
      %COMSPEC% /C (FONT.bat                                >> paste.htm
      echo     b%%%%00&#134;0000&#134;0000&#134;00%%%%d     >> paste.htm
      %COMSPEC% /C FONT).bat                                >> paste.htm
      echo              set ramdrive=%%%%d                  >> paste.htm
      %COMSPEC% /C BR.bat                                   >> paste.htm
      echo ECHO  ramdrive=%%ramdrive%%                      >> paste.htm
      %COMSPEC% /C BR.bat                                   >> paste.htm
      echo                                     SET ramdrive=>> paste.htm
      START paste.htm
      ERASE paste.htm /p
      CLS
      DEL (FONT.bat
      DEL FONT).bat
      DEL    BR.bat
      DEL (TEXT.bat
      DEL TEXT).bat


    ECHO ON/OFF in a second/another COMMAND.COM session.
    If errorlevel "bennyLevel" if not errorlevel "bennyLevel"

 Benny wrote:
    %windir%\command\EBD\FINDRAMD
    FOR %%d in (PROMPT:$ CTTY:NUL) do %%d
    FOR %%d in (Z...C) do IF errorlevel H%%d %COMSPEC% /C  [Snip] ECHO %%d

 Todd wrote:
    What good is displaying the value if you can not use it later?
    Note, the original prompt is not restored.
    If one wanted to only display the ramdrive letter, one could
    eliminate the PROMPT and both CTTY commands.

    FOR %%d in (Z...C) do IF errorlevel H%%d %COMSPEC%/C ECHO Ramdrive=%%d

    Still no SET command in sight, no extra blank line from CTTY, no 'file
    not found' message to mask, and the prompt is not altered. Also, one
    should not assume EBD exists on unknown systems, or that the user copied
    FINDRAMD.EXE into %windir%\command directory (mine has neither).

 Benny wrote:
    Yes you right about that! My reson for the code was not a program but
    a syntax solution. Now, you found that it's okay to reverse the order
    Z...A and use a "%COMSPEC% /C". This is much better... (Thanks Todd).

    ECHO is not OFF in a second COMMAND.COM session.

    A general conclusion:
    If it's about avoiding the SET command and still be able to executing
    particular commands, then it would normally be necessary to neste two
    IF statements. Example: IF errorlevel "A" IF NOT errorlevel "A +1"...
    My previours research about the bennyLevels (I never told about this)
    shows that it's NOT possible to create such two nested IF statements.
    The solution for this problem seems to be, a reverse order of all the
    elements in the FOR loop and this in combination with "%COMSPEC% /C".

    If it's just one command that we wanted, then the

    FOR %%d in (Z ... A) do IF errorlevel H%%d %comspec% /c SOMETHING...
    is useful.

    What I was trying yesterday was to figure out how to do an "ECHO OFF"
    in a second/another COMMAND.COM session.

    After a good sleep, I just found what I was searching. It goes here:

    ctty:nul
    FOR %%d in (Z ... A) do IF errorlevel H%%d %comspec% /c for %%v in (
echo:off ctty:con echo.%%d %%d: cd\ md:test pause cls) do %%v

    The above don't have to be used in combination with errorlevels. The
    point is that the "ECHO OFF" works in the second COMMAND.COM session
    and no SET commands are used ;-)


Reverse order of lines

Notis that line number 8 got wrapped:

@echo off %( Reverse all lines of a file by Benny Pedersen )% >%temp%.\~
for %%_ in (fB800:0LFA0''20''1F q) do echo %%_>>%temp%.\~
if exist %windir%\command\debug.exe %windir%\command\debug.exe<%temp%.\~>nul
if exist %windir%\command\SED.EXE goto GNU_SED (size unZIPed is 90.624 byte)
echo %windir%\command\SED.EXE was not found.
goto drag
:GNU_SED
   %(Line 08)% if not exist %1 call for %%_ in (ech got) do %%_o Drag & drop
:: %(Line 08, REMOVE THIS AND UNWRAP THE TEXT)% :: a file on the batch icon!
if exist %temp%.\out.txt del /p %temp%.\out.txt
if exist %temp%.\out.txt for %%_ in (echo goto:drag) do %%_ Ok so, quit!
SED.EXE 1!G;h;$!d %1 > %temp%.\out.txt
for %%_ in (dir pause cls) do %%_ %temp%.\out.txt
if exist %windir%\explorer.exe %windir%\explorer.exe %temp%.
REM or:                        %windir%\explorer.exe %temp%.\out.txt
:drag
del %temp%.\~


Calculating and converting or use this method...

X = dec2hex(160(n-1)) and the range of n is [1;25] (dec).
Example: if n = 2, then X = A0

Instead of writing a batch, which calculates and converts
the above result (X), then we can write 25 lines as:

if %n%==1  set X=00
if %n%==2  set X=A0 ... and so...
if %n%==25 set X=F00  but we can also use the following method:

          @echo off>~.bat
          for %%v in (0 A 14 1E 28 32 3C 46 50 5A 64 6E 78 82 8C 96 A0 AA B4
 BE C8 D2 DC E6 F0) do echo.   @set %%1=%%v0>>~.bat

          set n=2
          find ""/v/n<~.bat |find "[%n%]">~.bat

Compare the size of the above batch code with other methods.
Ok, here's the script:

          rem>~.scr
          for %%v in (f100L7''9 w q) do echo %%v>>~.scr
          debug ~.bat<~.scr>nul

Since n = 2, then
          CALL ~ X
would put A0 (hex), ((n-1)(2)(80) (dec) = 160n -160 (dec)) into
a variable named X.

Notes: The above method, (using FIND ""/v/n), can be used on big files, (any
number of lines [1;65535] and not just as the above example were I used, the
range [1;25] so, I have substituted "echo.@" with "echo.   @" and L4 with L7
in the above FOR loop and in the small script).


-Top- Page 2 | Trash