Menu Batch & Utility
Lesson 1
Menu
Last Updated April.
Home Links DOS Help

Search for
Get a Free Search Engine for Your Site

---Menu---

INPUT from a user
  What
  Strings
  Batchman
  Choice
     NT user
DATA - TEXT
  Length, Find, FindC
  Left, Right, Mid
  Parse
  Upper, Lower
  Repeat
  Val, Char

  SED.

OUTPUT
INPUT from a file
  Updated, (see Equal.bat).
  Read
INPUT from/about the system
  Updated and removed to section 14

DATA - NUMBERS (Math)
  Add, Sub, Mul, Div
  Convert
  Parsed with commas
Copy Con2file
COLORS
LOOPS (Add a new loop. See More Loops)

NOT, AND, OR, XOR
INTERRUPT
I/O PORT

Right Click Desktop - New Batch File
Right Click Batch File To Editor

 

# COLORS.

@Echo off
::
:: Batchman CLS %Number%
::
   Batchman CLS 31
   Echo Clear screen - This is white text and blue background.
   Batchman cEcho 47, Hello World
   Pause


:: Batchman cEcho C
::
   Batchman CLS 26
   Echo  Green text in 1th and
   Pause > NUL

   Batchman cEcho C 63,---Text in
   Batchman cEcho   63, line number two---
   Batchman cEcho C 63,---Text in the third line.---
   Pause > NUL


:: Batchman WINDOW %Define%
::
   Batchman window 002,004,00023,000002,00095
:: REMember        row,col,width,height,color,-=

   For %%v in (Echo."Green text in 3th line" "Pause>NUL" "CLS>>CON") do %%v


   See more stuff about colors

---Menu---
  

# GET INPUT.

   Batchman CLS 15
   For %%v in ("200,002" "400,002" "300,007" "500,006") do Batchman beep %%v
   For %%v in (200,2 400,2 300,7 500,6 200 400 300 500) do Batchman beep %%v


:: Redirect CON to a file. (try it at the DOS prompt:)
::
   Copy CON Some.tmp
   REM  Type F6 (or Ctrl+z), then Enter
   Edit Some.tmp


:: What C
::
   What C " Type: "
   If %What%!==~! Echo [Enter]
   If %What%!==!  Echo [Space] - [,] - [Tab]
   If %What%!==! Echo [Esc]
   If %What%!==A! Echo [A] - [a]

:: What S
::
   What S " Type and Enter: "
   If %What%!==!  Echo [Enter]
   If %What%!==A! Echo [A]
   If %What%!==a! Echo [a]
   Set what=


:: Strings x=ASK [Prompt][,Max chars][,1=No echo]
::
   Strings in=ASK  Type and Enter:
   Echo [%in%]
   If %in%!==! Echo    [Space] - [,] - [Tab] - [Enter]

:: Strings x=GETKEY
::
   Strings x=GETKEY
   Echo  [ASCII value and Scan code] = [%x%]
::
::      [M]= [77 50],  [m]= [109 50],  [A]= [65 30].
   Set x=



:: Batchman GETKEY
::
   echo Type:
   Batchman getkey
   if errorlevel 50 if not errorlevel 51 echo [M] or [m]
   if errorlevel 28 if not errorlevel 29 echo [ENTER]
   if errorlevel 57 if not errorlevel 58 echo [SPACE]
   if errorlevel 01 if not errorlevel 02 echo [ESC]
   if errorlevel 14 if not errorlevel 15 echo [BACKSPACE]


:: Batchman GETKEY %numbers%
::
   Echo Type: [F1], [F3], [F11] or [F12]:
   Batchman getkey 1 3 11 12


:: Batchman GETKEY '%permitted%'
::
   Batchman CLS 126
   Echo.#        [Ctrl+Break] do [ESCape] - [Alt+F4].
   Echo.
   Echo.   Type:  [A], [a] or [Esc]
   Batchman getkey 'a'
   If NOT errorlevel 2 Echo    [A] or [a]
       If errorlevel 2 Echo    [Esc] or [Ctrl+C]



:: Choice /C: [Without extra info, Switch /N] [Time-Count-Down, Switch /T:]
::
   Batchman CLS 127
   Echo.#        [Ctrl+Break] or [Ctrl+C] do [ESCape]  ^C.
:  TEST #
   Echo.
   Set EL=
   Rem  ASCII 27 - ASCII 7
   Choice /c-+q /n/t-,9    Hit:  Minus[-], Plus[+] or [q] to Quit(Esc) 
::
   If errorlevel 00003                 Set EL=C: Q(Esc) [3 or greater: 3-255]
   If NOT errorlevel 3                 Set EL=B: - or + [Less than 03: 2-000]
   If errorlevel 1 If NOT errorlevel 2 Set EL=A: Sure - [       Exact: 1    ]
::
   If NOT %EL%==C: Batchman cEcho 63,   [-] or [+] ... ?  [%%EL%%]=%EL%
   If %EL%==A: Batchman cEcho 000095,   Not [+] but [-].  [%%EL%%]=%EL%
   If %EL%==C: Batchman cEcho 000079,   The END is near!  [%%EL%%]=%EL%
::
:: FOR %%V IN (ECHO. "GOTO TEST") DO %%V
:: FOR %%V IN (ECHO. GOTO:TEST ) DO %%V
   FOR %%V IN (ECHO GOTO) DO %%V TEST - I WILL GOTO!
:: FOR %%V IN (ECHO GOTO) DO %%V.  %1
:: FOR %%V IN (ECHO. %0%    ) DO %%V


   An example for NT users (includes an Qbasic file).
   http://mspress.microsoft.com - CHOICE ERRORLEVEL note

---Menu---
  

# GET INPUT - FROM A FILE.

@Echo off
::
:: Strings %Variable%=READ %File%, %Line_number%
::
:: Equal.bat - Compare two files.
:: Drag and drop a file - Then another file.
:: Alternative - You can write:  equal file_name.
::
   C:
   Cd %temp%\
                              Echo %1 >> Equal
                      Strings Equal=READ Equal,1
                          If %Equal%==%1 EXIT
                 For %%v in (%Equal% %1) do Echo .....%%v
                      FC.exe %Equal% %1| Find ":" > Equal
                                 Strings Equal=READ Equal,2
                                If not !%Equal%==!FC: Echo -NOT-
                                     Set Equal=
  For %%v in (Echo Pause Del CLS) do %%v Equal

   NOTE: The above file is updated, (see Equal.bat).

---Menu---
  

# GET INPUT - FROM THE SYSTEM.

updated and removed to section 14

# TEXT.


   Strings x=LENGTH AbCdefGh
   Echo [%x%] = Distance: [8]

   Strings x=FIND AbCDefGh, dE
   Echo [%x%] =     [4]

   Strings x=FINDC AbcdefGh, dE
   Echo [%x%] = [0]  Cause: 'de' is not the same.


   Strings x=LEFT AbCdefGh,4
   Echo [%x%] =  [AbCd]

   Strings x=RIGHT AbCdefGh,4
   Echo  [%x%] =      [efGh]

   Strings x=MID AbCDefGh,4,2
   Echo  [%x%]  =  [De]


:: String, Token n, Token separator
   Strings x=PARSE 208'240'48,%n%,'
   if '=='%x% set x=176


   Strings x=UPPER aBcdefGH
   Echo [%x%] =   [ABCDEFGH]

   Strings x=LOWER AbCdefGh
   Echo [%x%] =   [abcdefgh]


:: A string of n characters c.
   Strings x=REPEAT n of chars, c

:: See a program where I use the 'Strings REPEAT' command, click here.

   Set x=a
   Strings character=UPPER %x%

   Strings ascii_val=VAL %character%
   Echo  (%ascii_val% )= ASCII( %character% )         (65)= ASCII(A)

   Strings character=CHAR %ascii_val%
   Echo  ( %character% )= Character( %ascii_val% )    (A) = Character(65)

   For %%v in (x character ascii_val) do Set %%v=

:: Created Feb 6, 2001:
@echo off
 strings x = ask Input a character or an ASCII value: ,3
 strings q = length %x%
 if not %q%==1 for %%S in (echo.GET:s s goto:end_s) do %%Strings/p:CHAR %x%:
 for %%S in (echo.GET_ASCII:[char[%x%]]:s s) do %%Strings/p:val %x%:
:end_strings
 for %%v in (set:x set:q set:cmdline echo echo pause cls) do %%v=


---Menu---
  

# NUMBERS - (Math).

Add, Sub, Mul, Div.

:: Strings %Variable%=ADD|SUB|MUL n1, n2[,n3][,n4]... [,n10]
::
   Strings x=ADD 2,3
   Echo [%x%] = [5]

   For %%v in ("rem Set X=290" "Set b=300" "Set a=10") do %%v
   Strings x=SUB %b%,%a%
   Echo  -(-%%b%% +%%a%%) = +(-%a% +%b%) = %b% -%a%, So %X% = 290
   For %%v in (a b) do Set %%v=

   Strings x=MUL 4,3
   Echo [%x%] = [12]

   Strings x=DIV 9,4
   Echo [%x%] = [2] 

Convert

:: Syntax: Strings %Variable%=CONVERT n, New Base

:: Examples:

   Strings x=CONVERT 255, 16
   Echo   [FF] = [%x%]

   Strings/b16 x=CONVERT FF, A
   Echo  [255] = [%x%]

   Goto MORE_CONVERT & ALL-ROUND LOOP


::h2d.bat -- Hex to decimal -- BTW. about the w0; thanks to Tom L.
@echo off
echo.. | choice /n /c%1. > nul
if errorlevel 6 goto end > %temp%.\~.scr
if not errorlevel 2 goto end
for %%v in (F0L%1''A rCX %1 w0 q) do echo %%v>> %temp%.\~.scr
type %temp%.\~.scr | debug %temp%.\~.scr> nul
find /v /c "" <%temp%.\~.scr
:end
del %temp%.\~.scr

::dec2bin



Parsed with commas

n parsed with commas every 3 digits. Syntax: Strings x=ADDCOMMAS n

 
: Loop3
  Strings V=CONVERT %X%,%Base%
  Echo. [%V%]=C(%X%)>>file
  Strings X=ADD %Step%,%X%
  Strings v=DIV %Last%,%X%
  If not %v%==0 Goto Loop3
 
: End
  For %%v in (Base X Last Step v) do Set %%v= 
  For %%v in (Echo. Echo. Pause Cls) do %%v
  If Exist file Type file|More
 
16
17. Substitute to what ever
18.
19
20
21
22
23
24
25
26. Output file to screen.

 
: MORE_CONVERT & ALL-ROUND LOOP TEMPLETS
::--------------------------------------
  For %%v in (Echo Break) do %%v off
 
      If Exist file Del file /P
      If Exist file Goto End
 
      If (%Base%)==() Set Base=16
      If    (%X%)==() Set X=0
      If (%Last%)==() Set Last=255
      If (%Step%)==() Set Step=100
:: -----------------------------------------  
                      Set v=1
  If not %X%!==0! Strings v=DIV %Last%, %X%
  If %v%==0  Goto End
  If !%Step%==!0  Strings Step=ADD %Last%,1
  Goto Loop3|             Echo.
 
 
 
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11.
12.
13. Quit, if X > Last      
14
15


---Menu---
  

# OUTPUT.

    Echo 123 > CON
    Echo 123 > PRN
    Echo 123 > LPT1
    Echo 123 > NUL
  Console
  Printer
  Parallel port number 1
  Nul Device

:: Redirection to a file.

:: The following example shows a lot about the behaviour of Windows98
:: It may look advanced. So please donīt blame me for using your time
:: to show you the trouble. It's better to see it all now than later.
::
:: Introduce Write.com
::
   C:
   Cd %TeMP%\
                             Echo.>                  "My Tempor.text"
                             Echo.# ~~ Hi Mum! ~~ #>>"My Tempor.text"
                             Echo #Send more money#>>"My Tempor.text" 
                        Write.com # Kind regards>>   "My Tempor.text"

   Type "My Tempor.text"     >    12345678901234567_____.TEMP

   Strings /p* write 123456~1.tem*              , #
       Strings write 123456~1.tem,# ~~  * Me!  ~~ #

               Type "123456~1.tem"        >           MyTemp~1.tex

               Start /w Notepad                      "My Tempor.text"
                        Del                          "My Tempor.text"
                        Del      "12345678901234567_____.Temp"
@echo off %[updated Feb 25, 2001]%
echo. %0? | find /i ".bat?">nul
set @=%0
if errorlevel 1 set @=%0.bat
find "%%@%% "<%@%>CRLF.BAT
set @=
for %%v in (goto:@ L102 W F100LFF''1A L W102 Q :@) do echo %%v>>CRLF.BAT
goto p
:: if not !==!%@% set @=
find /v%@% "@"<%0 |debug %1>nul
copy /a%@% %1 +nul %1>nul
:p
echo Line 1 > test.tmp
call CRLF.BAT test.tmp
echo Line 2 >>test.tmp
for %%v in (del cls) do %%v CRLF.BAT


---Menu---
  

# OTHER.



:: The logical NOT of n.
   Strings x=NOT n

:: The logical AND of the parameters.
   Strings x=AND n1,n2[,n3][,n4]... [,n10]

:: The logical OR of the parameters.
   Strings x=OR n1, n2[,n3][,n4]... [,n10]

:: The exclusive OR of two numbers.
   Strings x=XOR n1,n2



:: The registers from an interrupt. Dangerous!
   Strings x=INTERRUPT Int n,AX,BX,CX,DX,DI,SI,BP,DS,ES

:: Returns status of programs hooked to the Multiplex Interrupt.
   Strings x=2FCHECK n or Alias
 

   A byte from an I/O port.
   Strings x=IN Port number

:: Writes a byte to an I/O port.
   Strings x=OUT Port n, Output byte

---Menu---
  

# SED


:: Versions of SED do differ.
:: Tips: Download and rename SED15.EXE to C:\Windows\Command\sed.exe
::
:: If a line ends with a X, append the next line:

   SED -e :a "/X$/N;s/\n//; ta;" INFILE > OUTFILE

:: Returns long name (directory) and file name(s) :: Drag and drop, a file or directory to the icon :: :: Used: PFE32.EXE (editor) + SED. (text utility) :: If %1!==! For %%c in (pfe32 Exit) do %%c %0 For %%c in (LS : D) do C%%c %temp%\ Set v= :: If not exist %1/nul Set v=\. If exist %1\nul Set v=\. :: Dir %1 | Sed "/\\/!d;s/.:/\n&/"|Sed "/:/!d" >a Dir %1|Sed "/\\/!d;s/.*\(.:\)/\1/">a Attrib %1%v% | Sed "s/.\{27\}//" >>a Set v= For %%c in (Pfe32 Pause Del Cls EXIT) do %%c a ---Menu---

Top | Download_&_Links | Tables | Win9x_&_BATch_Tips

 

Links:

deja: [alt.msdos.batch] | Bob_Watson: [About DOS-7] | Rob van der Woude: [Scripting Pages] | wtnewton: [Batch Programming Stuff] | Eric Pement: [About SED] | Ted Davis: [T.e.d.'s Personal Links] |   [Batfiles] | maem.umr.edu: [Internal and Intrinsic Commands] | webspace: [Batch Programming] | zdnet: [Date in a NT 4 Batch File] | computerhope: [Information on batch files] | Tom: [Batch File Applications] | uwasa.fi: [collection of links] | Dev Teelucksingh: [Interesting DOS programs] | Frank-Peter Schultze: [fpschultze] | Peter Madsen: Config.sys & Autoexec.bat]

 

Still don't find it? - Try Carlo's URL Collection!