|
From the News Page 5 | |
Truncating.
Mouse in Batch. Quick Overview.
Back Space to remove stuff in the FRONT of a string.
CTTY -- John Savage
Six nested FOR LOOPs isn't a problem.
Transforming.
Address book.
A new and much faster EXIT PROMPT technique were found.
-- Go into and back from the TEMP environment.
Time.bat -- Something to study.
Extract.bat -- Extracting system files for Win9X.
Input and Redirection
Truncating
Technique. Using reversed order of %1 and %2.
Constructed under Win98:
@ECHO OFF
IF (%1)==() %0 0045 0083
ECHO (%1) (%2)
PAUSE
IF NOT (%3)==(!!!!) FOR %%0 in (" ") do %0 %%%2 %1 !%3
ECHO :-)
MOUSE.BAT
Mike Jones code in use, are waiting for a mouse click.
(Under full screen DOS, the mouse cursor would be on).
ECHO e100 B8 1 0'3'DB CD'3'B0 3'C'CD'3'B DB't'FA 91 D3 EA D3 E8 91 C3>ax.dat
FOR %%! in (.g116 .q) do ECHO%%!>> ax.dat
DEBUG < ax.dat | FIND "X" >> ax.bat
Could be used as above, (or in ONLY one line as shown in line no f).
Notis: Tested under Win98. ----- Three lines maybe unwrapped: -----
Line no 4: (209 char long) %COMSPEC%....bat$gNUL$_CALL ~>Digits.bat
Line no f: (121 char long) %comspec%....8$_q|debug|find "X">>ax.bat
Line no m: (195 char long) FOR %%!......do CALL %0 goto:w %2 %3 %%!
Quick Overview:
1...4 Create Digits.BAT: BATch file to add hex numbers.
56 Clear, and fill up the screen.
789a Echoing a ruler: TOP and LEFT.
df Label named Mouse: Mike's code is waiting for the mouse click.
efg Where was clicked: AX.BAT to get two numbers, (4 digits each).
hi Remove the prefixed zeros, (2 digits each).
kl Displaying that position in the 25'th line.
mnopw Formula in 3 lines calculating/converting the location, (to be
used, if one would echoing something where the mouse clicked).
q Echoing something where the mouse liked to click, (color = F).
r...v IF clicked in the upper left corner: Won't repeat Mouse, Exit.
Troubleshooting with a double colon in front of line f and use f'0...f'z:
::% f% %comspec%....8$_q|debug|find "X">>ax.bat
% f'0% :: ------- Mouse imitation, troubleshooting -------
% f'1% if %COL%!==! set COL=47 %[set whatever in 00...4F]%
% f'2% if %LIN%!==! set LIN=18 %[set whatever in 00...18]%
% f'3% echo AX=blah BX=blah CX=00%COL% DX=00%LIN%>>ax.bat
% f'4% call digits= 2, COL=add 00%COL% 0001
% f'5% if %COL%==50 set COL=00
% f'6% if %COL%==00 call digits=2 LIN=add 00%LIN% 0001
% f'z% if %LIN%==19 set LIN=00
% g% AX
Benny Pedersen,
Toggles between full screen DOS and a window:
Hold the left ALT key and press the Enter key
(not the Enter key on the numb keyboard but the one to the left).
@%1 echo off
% 2% FOR %%! in (%temp%.\ CD) do %%! %temp%.
% 3% ECHO:,EXIT[>~
% 4% %COMSPEC%<~/kPROMPT ECHO h%%4 %%5$g~.bat$_ECHO q$g$g~.bat
$_debug$L~.bat$g$g~.bat$_%COMSPEC%$L~/kPROMPT f1%%1LC D A 1A 9
$$_m11DL4 1%%1$$_eC'SET %%2='$$_rcx$$_E$$_wC$$_q$bdebug ~.bat$
gNUL$_CALL ~>Digits.bat
% 5% MODE Co80
% 6% %comspec%<~/kprompt fB800:0LFA0 A'x'$_q|debug>nul
% 7% SET pos= fB800:0 9E
% 8% %comspec%<~/kprompt%pos%'0{1p2p3p4p5p6p7p8p9pApBpCpDpEpFp'$_q|debug>nul
% 9% FOR %%! in (. 1 2 3 4 5 6 7 8 9 A B C D E F) do ECHO %%!
% a% FOR %%! in (0 1 2 3 4 5 6 7) do ECHO 1%%!
% b% :: Waiting for a mouse who need a click. YES! My English is better now.
% c% :: Yesterday I would said: Press or Hit any mouse to continue...
: d Mouse
% e% echo.IF NOT %%1!==! %0 goto:h %%7 %%5>ax.bat
% f% %comspec%<~/kprompt e100 B8 1 0'3'DB CD'3'B0 3'C'CD'3'B DB
't'FA 91 D3 EA D3 E8 91 C3$_g116$_q|debug|find "X">>ax.bat
% g% AX
: h Remove two prefixed zeros from each parameter:
% i% IF NOT %4'==!!!!' FOR %%0 in (" ") do %0 goto:h %%%3 %2 !%4
% j% :: Echoing the position in the 25'th line:
% k% %COMSPEC%<~/kPROMPT eb800:F07'%2/'$_eb800:F06'%2$h/'$_q|debug>nul
% l% %COMSPEC%<~/kPROMPT eb800:F0D'%3/'$_eb800:F0C'%3$h/'$_q|debug>nul
% m% FOR %%! in (18 78 17 73 16 6E 15 69 14 64 13 5F 12 5A 11 55 10 5
0 0F 4B 0E 46 0D 41 0C 3C 0B 37 0A 32 09 2D 08 28 07 23 06 1E 05 19 0
4 14 03 0F 02 0A 01 05 00 00) do CALL %0 goto:w %2 %3 %%!
: n Formula including the above line and the 2 below, ((%2)50 +%3)2h.
% o% CALL Digits= 3, pos =add 0%20 00%3
% p% CALL Digits= 3, pos =add 0%pos% 0%pos%
% q% %COMSPEC%<~/kPROMPT eb800:%pos%'#'F$_q|debug>nul
% r% IF NOT %2%3==0000 GOTO d Mouse
% s% DEL %temp%.\ax.?at
% t% DEL %temp%.\~.*
% u% DEL %temp%.\Digits.bat
% v% FOR %%! in (SET CLS EXIT) do %%! pos=
: w Sub
% x% IF %pos%!==next! %0 goto:n %4 %3
% y% IF %2!==%4! SET pos=next
: z EOF
:: Quick Overview.
Back Space
Please substitute any # characters below with
a Back Space Character instead.
@%1 echo off
SET X=01
FOR %%0 in (# = Back Space, ASCII 8.) do %0 goto:Y %%%X%
:Y
echo.(%2)
FOR %%%% in (-#, Minus and Back Space) do %0 goto:Z %%%2
:Z
echo. Result: (%2)
goto EOF
The Back Space character is not only handy for
removing ending stuff (%variable%$h$h syntax) but
can also be used for removing leading characters
from a parameter.
The above batch demo shows how to remove the zero in %X%.
Not (01) but only (1) would be displayed.
Since John Savage has used such, then it isn't new stuff.
(John Savage is one who are able to neste 3 FOR loops and
like to find alternative ExitPrompt syntax, etc.).
The new thing is, that an extra file isn't needed.
If X=85, then (85) and NOT %85 would be displayed.
I.e.: the second FOR loop is solving that problem.
If %X% is not 01 but 85, then another problem (%85) could
be solved by using an extra file but writing to disk isn't fast.
First the leading zero in 01 is substituted with a Back Space
character, (to write such in the DOS EDITor:
Press Ctrl P followed by ALT 8, (num keys)), then the
Back Space is prefixed with a minus to be eated
by the Back Space and the result would be (1).
If X=85, then the first FOR command ofcause
would prefix the 85 with percent (%85). The second FOR command
is then used to substituting the percent in %85 with:
Minus and Back Space, so, the problem were solved.
Benny Pedersen,
PS.
The following may also be used but with other results:
Scripting purposes in a FOR Loop:
FOR %%%% in ('',two single quotes) do %0 goto:Z %%%2
Substituting the next character, (if = 1):
FOR %%1 in (#,Back Space) do %0 goto:Z %%%2
echo. (some space here) %2.
etc...
:EOF
CTTY
Here's an old file from November 19, 2001.
Today is December 3, 2001, so if I rewrite
it today, then it would NOT be the same as
written! but anyway, here:
@ECHO OFF
GOTO (%1)
Hi,
This demo batch uses an old discovery by Laura.
If using the CTTY thing in a sub routine executed
with %COMSPEC%/c, then the "Open Files Problem"
would be solved.
Benny Pedersen,
BTW. Notis that the "Invalid Device Error Message"
(in any OS language), is solved by using a file
with "CTTY >>" instead of "CTTY >",
:() -----------------------------------------------------------------
:: Create a file named ~ (with CR but without LF)
FOR %%! in (%temp%.\ CD) do %%! %temp%.
ECHO EXIT|%COMSPEC%/kPROMPT n~$_e0'EXIT['d$_rcx$_6$_w0$_q|debug>NUL
:: ----------------------------------------------------------------
%COMSPEC%/k PROMPT $_ That's it :-) $_$_$_$_ <~
%COMSPEC%/c%0 Sub,
FIND /v "EXIT[" <~ | FIND " " >~
NOTEPAD ~
PAUSE Want to recall, then use either "GOTO ()" or "%0" here.
CLS
GOTO EOF
:(Sub) ---Lines with ECHO. got a space character after the dot:
CTTY>>~
ECHO.
ECHO. Hello!
ECHO.
FOR %%! in (1 2 3 4 5) do ECHO. %%!
%COMSPEC%/k PROMPT $_ _____________$_ $b $b$_<~
%COMSPEC%/k PROMPT $_ $b It works. $b$_ $b_____________$b$_<~
ECHO.
ECHO. All is done, EXIT...
ECHO. PS. :-)
CTTY CON
:EOF
Are SIX Nested FOR LOOPs a problem? NO it isn't!
@echo off
for %%1 in (1) do command/cfor %%2 in (2) do command/cfor,%%%%%%%%3,in,(3
,),do,command/cfor %%%%%%%%4 in (4) do command/cfor %%%%%%%%%%%%%%%%5 in (5)
do command/cfor %%%%%%%%%%%%%%%%6 in (6) do echo: (%%1 %%2 %%3 %%4 %%5 %%6)
:: It is ofcause obviours that the next one, i.e. the
:: 7'th FOR loop is getting 32 percent char (if the same pattern existing) ?
pause
cls
exit
I have comma delimited the 3'th loop, which may be useful in case that
you want to redirect with CTTY>file along with a filter as FIND " "/v.
December 12, 2001:
John Savage wrote: Uh huh. Is it April already??
No, it would also works in both May and June...
@GOTO kangaroo bat
9 FOR loops wouldn't be a problem but since the line would be
to long, (only one or two elements in each loop), then I have
only nested 8 FOR loops as shown below.
Benny,
BTW. The ~ file would contains 1908 lines (before filter) and
384 lines in the file for output, (it would take some time!).
:Kangaroo bat
:: Goes TEMP (includes another TEMP Drive Specification than current:)
if not (%temp%) == () for %%f in (%temp%.\ cd) do %%f %temp%.
:: No prompting:
prompt $
:: Create a file into the TEMP environment:
rem > ~
:: 8 FOR LOOPs (UNWRAP INTO ONE LINE:)
for,%%1,in,(A,B,C),do,command/cfor,%%2,in,(d,e),do,command/c
for,%%3,in,(f,g),do,command/cfor,%%4,in,(h,i),do,command/cfor,%%5,
in,(j,k),do,command/cfor,%%6,in,(l,m),do,command/cfor,%%7,in,(n,o),do,
command/cfor,%%8,in,(p,q),do,echo.%%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8>>~
:: Prompting something else and displaying the result:
prompt $p$g
find " " <%temp%.\~ |find "."/v> ~
for %%f in (type rem:del) do %%f ~
Benny Pedersen,
PS. For information about the CTTY Open-Files-Problem, see
http://users.cybercity.dk/~bse26236/batutil/NEWS5.HTM#ctty
BTW.
Extented loops (if a line get's to long), can be
created with only some few extra lines of batch:
To be found in the %temp% dir and must be named ~MY.BAT
Two lines, (line no 4 and 11) must be unwrapped.
@echo off
if !%0==!%temp%.\~MY:,goto:down
if !%1==! for %%! in (goto:begin ctty) do %%! nul
for %%t in (a b) do %comspec%/cfor %%u in (z y) do %comspec%/cfor %%%%%%%
%v in (! #) do %comspec%/c%temp%.\~MY: %1 %%t %%u %%v
echo.>con
shift
if not %1!==! %comspec%/c%temp%.\~MY %1 %2 %3 %4 %5 %6 %7 %8 %9
:u
for %%! in (1 2 3 4 5 6 7 8 9) do shift
if !==!%1 goto eof
for %%! in (%comspec% goto:u) do %%!/c%temp%.\~MY %1 %2 %3 %4 %5 %6 %7 %8
%9
:begin
call %temp%.\~MY.BAT 0 1 2 3 4 5 6 7 8 9 A B C D E F G H I J K
call %temp%.\~MY.BAT L M N O P Q R S T U V W X Y Z a b c d e f g h i j k
for %%! in (goto:eof ctty) do %%! con
:down
echo. %1 %2 %3 %4>con
:eof
Transforming
:: Transforming 07-?? into ??
:: for example: 07-38 into 38
@ECHO OFF
SET X=07-38
ECHO -----(%X%)-----
FOR %%0 in (%%) do SET X=%%%X%
FOR %%7 in (%%) do SET X=%X%
FOR %%- in (%%) do SET X=%X%
FOR %%0 in (0) do SET X=%X%
FOR %%1 in (1) do SET X=%X%
FOR %%2 in (2) do SET X=%X%
FOR %%3 in (3) do SET X=%X%
FOR %%4 in (4) do SET X=%X%
FOR %%5 in (5) do SET X=%X%
FOR %%6 in (6) do SET X=%X%
FOR %%7 in (7) do SET X=%X%
FOR %%8 in (8) do SET X=%X%
FOR %%9 in (9) do SET X=%X%
ECHO -----(%X%)-----
SET X=
Benny Pedersen,
PS. I think that this new method above can be used in also
DOS 6. The new method (I just found it today), is inspired
of some previours and older stuff which can be found here:
http://users.cybercity.dk/~bse26236/batutil/NEWS5.HTM#bs
Moreover.
Debug stuff isn't used. So, it maybe possible to go further
than this. Hmmm, the following line won't write anything to
the memory and won't write anything to a disk either, i.e.:
only the redirection with >> and pipes (|) are writing, so,
the "D" command in debug bears comparison with
the "DIR" command in a directory. For example:
ECHO EXIT|%COMSPEC%/kPROMPT db800:0 L10$_q|debug|sort/r>>%temp%.\B800.bat
I'm sure that the above "dir" command into debug maybe accepted by
those who havn't any enthusiasm for writing binary files or
using the RAM for such things. A DIR command would be harmless
and I'm sure that someone in the Batch News Group would be able to
confirm the comparison I just did about the "D" with the "DIR" command.
@ECHO OFF
ECHO 08-12-01 (December 8, 2001)
ECHO IF NOT %%1!==! GOTO !> %temp%.\B800.bat
ECHO EXIT|%COMSPEC%/kPROMPT db800:0 L10$_q|debug|sort/r>>%temp%.\B800.bat
ECHO :!>> %temp%.\B800.bat
ECHO FOR %%%%0 in (%%%%) do SET X=%%%%%%8>> %temp%.\B800.bat
ECHO FOR %%%%7 in (%%%%) do SET X=%%X%%>> %temp%.\B800.bat
ECHO FOR %%%%- in (%%%%) do SET X=%%X%%>> %temp%.\B800.bat
ECHO FOR %%%%0 in (0) do SET X=%%X%%>> %temp%.\B800.bat
ECHO FOR %%%%1 in (1) do SET X=%%X%%>> %temp%.\B800.bat
ECHO FOR %%%%2 in (2) do SET X=%%X%%>> %temp%.\B800.bat
ECHO FOR %%%%3 in (3) do SET X=%%X%%>> %temp%.\B800.bat
ECHO FOR %%%%4 in (4) do SET X=%%X%%>> %temp%.\B800.bat
ECHO FOR %%%%5 in (5) do SET X=%%X%%>> %temp%.\B800.bat
ECHO FOR %%%%6 in (6) do SET X=%%X%%>> %temp%.\B800.bat
ECHO FOR %%%%7 in (7) do SET X=%%X%%>> %temp%.\B800.bat
ECHO FOR %%%%8 in (8) do SET X=%%X%%>> %temp%.\B800.bat
ECHO FOR %%%%9 in (9) do SET X=%%X%%>> %temp%.\B800.bat
ECHO FOR %%%%! in (%%1 %%3 %%5 %%7) do ECHO %%%%!>> %temp%.\B800.bat
ECHO FOR %%%%! in (1 2 3 4 5 6 7 8 9) do SHIFT>> %temp%.\B800.bat
ECHO FOR %%%%! in (%%X%% %%1 %%3 %%5 %%7) do ECHO %%%%!>>%temp%.\B800.bat
FOR %%! in (CAL rem:DE) do %%!L %temp%.\B800.bat
If you take a look at %temp%.\B800.bat, then you would see
another discovery by me. It's about the filename followed by a colon.
OOPS. Sorry, this was a long PS.
BTW. Back Slash characters can still be useful when one would writing
to the CON:
ECHO EXIT|%COMSPEC%/kPROMPT Hello!!!$h$h$_
::ECHO EXIT|%COMSPEC%/kPROMPT db800:A0L10$_q|debug|sort/r
:: dump ---^
BTW. Extra information (not interesting),
:: Removes repeated elements without using any debug stuff:
::
@%1 ECHO OFF
SET D=08122001
FOR %%! in (0 1 2 3 4 5 6 7 8 9 10) do SET P%%!=.
::Try erase the dot at the end of the above line.
FOR %%! in (0 1 2 3 4 5 6 7 8 9 9 ) do CALL %0 GOTO:! %%!
FOR %%! in (0 1 2 3 4 5 6 7 8 9 10) do SET P%%!=
GOTO EOF
:!
ECHO %2'|CHOICE/C'%D%>NUL
FOR %%! in (10 9 8 7 6 5 4 3 2 1 0) do IF NOT ERRORLEVEL }%%! SET P0=%%!
IF NOT %P0%!==0! %COMSPEC%/cECHO. Found %2 on position P%P0% (was %%P%P0%%%)
IF %P0%!==0! ECHO. %2 was not found
%COMSPEC%/cIF %2==%%P%P0%%% ECHO. %2 repeated on P%P0%
SET P%P0%=%2
ECHO %P1%%P2%%P3%%P4%%P5%%P6%%P7%%P8%%P9%%P10%
GOTO EOF
If you have problems with the above Errorlevel: }%%!, then
you can substitute the "}" with the number "one" as below:
::ECHO %2'|CHOICE/C'%D%>NUL
ECHO %2'|CHOICE/C'''''''''%D%>NUL
FOR %%! in (...snip... IF NOT ERRORLEVEL 1%%! SET P0=%%!
or if you want to use the short Choice line without a "}",
then you can use "77" instead of "1":
FOR %%! in (...snip... IF NOT ERRORLEVEL 77%%! ...snip.
It would still be BennyLevels but with a number instead of
a character.
BTW.
The computer magazine which described this technique named
Bennylevel, wrote that the person who invented this method
were the first Danish person in a computer world which got
something named. Anyhow funny because: No one from Denmark
knows anything about where or who I am or what I am doing.
:-)
Benny Pedersen,
http://users.cybercity.dk/~bse26236/batutil/help/INDEX.HTM
:EOF
Moreover:
Below are some additional information (different solutions to be evaluated:)
@ECHO OFF
SET X=%%07-38
FOR %%0 in (%%) do SET X=%X%
FOR %%7 in (%%) do SET X=%X%
FOR %%- in ($Q) do SET X=%X%
CHOICE/c12345 What Solution
FOR %%! in (2 3 4 5) do IF errorlevel %%! GOTO %%!
:1
ECHO::EXIT>~.bat
%COMSPEC%<~.bat/kPROMPT SET X%X%$_>>~.bat
GOTO Result
:2
PROMPT ::$h$h%PROMPT%
%COMSPEC%/cFOR %%! in (PROMPT ::) do %%! SET X%X%$_>~.bat
GOTO Result
:3
%COMSPEC%/cFOR %%! in (1 2) do PROMPT SET X%X%$_|find "=">~.bat
GOTO Result
:4
ECHO EXIT,%%|%COMSPEC%/kPROMPT SET X%X%%%>~.bat
GOTO Result
:5
ECHO EXIT|%COMSPEC%/kPROMPT SET X%X%$_:>~.bat
:Result
CALL ~.bat
ECHO (X) = (%X%)
Address book
Input text and Enter without using debug.
Press Enter after each input (3 lines of input).
If you want to input 4 lines instead of 3, then you can modify and write
FC /n/Lb4 NUL CON. (don't use: FC /n/Lb2 CON CON in this batch example:)
@echo off
goto -%1-
:-- input
FOR %%1 in (-- Name: Address: Country:) do ECHO. %%1
FOR %%v in (%temp%.\ CD) do %%v %temp%.
REM > %temp%.\1~.bat
FOR %%! in (0 1 2 3 4 5 6 7 8 9) do echo.>> %temp%.\1~.bat
FC /n/Lb3 NUL CON | find ": " >> %temp%.\1~.bat
echo:if 1:==%%1 %0 Output Name... %%2 %%3 %%4>%temp%.\11.bat
echo:if 2:==%%1 %0 Output Address %%2 %%3 %%4>%temp%.\12.bat
echo:if 3:==%%1 %0 Output Country %%2 %%3 %%4>%temp%.\13.bat
FC /n NUL %temp%.\1~.bat | find " 11: " >>%temp%.\11.bat
FC /n NUL %temp%.\1~.bat | find " 12: " >>%temp%.\12.bat
FC /n NUL %temp%.\1~.bat | find " 13: " >>%temp%.\13.bat
FOR %%1 in (1 2 3 ) do CALL %temp%.\1%%1.bat
FOR %%1 in (echo echo:Continue choice cls) do %%1: --
IF NOT ERRORLEVEL 2 GOTO -- input
FOR %%1 in (1 2 3 ~) do DEL %temp%.\1%%1.bat
DEL /p %temp%.\AddressBook.txt
GOTO EOF
:-Output-
ECHO: %2: %3 %4 %5
ECHO: %2: %3 %4 %5>> %temp%.\AddressBook.txt
:EOF
: Related links: FC/n/Lb1...
New EXIT PROMPT technique
This batch code is useful when you want into the TEMP environment:
@ECHO OFF
ECHO.:EXIT>%temp%.\goback.bat
%COMSPEC%<%temp%.\goback.bat/kPROMPT $N:$_CD $P$_>>%temp%.\goback.bat
FOR %%v in (%temp%.\ CD) do %%v %temp%.
::
FOR %%c in (CAL DE) do %%cL %temp%.\goback.bat
Notes:
The new EXIT PROMPT technique were found in an interesting discussion,
December 29, 2001 in the Batch News Group, "Subject: Generate a 10,000
line file really quickly?". Someone said that it would be difficult to
measure the run time but after several experiments, then I can now say
that the new method as shown above, is twice as fast than my previours
discovery. The previours "EXIT PROMPT" technique is one line less than
the new technique but one pipe (|) were used for redirection.
Time.bat
Something to study.
The following batching is based on a previours discovery, transforming.
Please unwrap line no seven.
@%1 ECHO off
ECHO.:exit|%COMSPEC%/kPROMPT %0 goto:x $t$_>%temp%.\~.bat
FOR %%f in (CALL DEL GOTO:eof) do %%f %temp%.\~.bat
:x
IF (%x%)==() SET x=%%%2%3%4%5%6%7%8%9
ECHO %x%'|CHOICE/s/c'()'''-.'0123456789:''''''ABCDEFGHIJKLMNOPQRSTUVWXYZ[\
]^_`abcdefghijklmnopqrstuvwxyz{'}~>NUL
FOR %%e in (. 0 1 2 3 4 5 6 7 8 9 : a p) do If errorlevel 1%%e SET e=%%e
FOR %%%e% in (%%) do SET x= %x%
:: FOR %%"/" in (%%) do SET x=%x%
ECHO. %e% & %x%
FOR %%e in (0 1 2 3 4 5 6 7 8 9) do IF %%e==%e% SET ee=%ee% %e%
If not %%==%x% goto x
ECHO.%ee%
FOR %%v in (x e ee) do SET %%v=
:eof
:: ECHO %x%'|CHOICE/c'''''''.'0123456789:''''''A''''''''''''''P>NUL
:: FOR %%e in (. 0 1 2 3 4 5 6 7 8 9 :) do If errorlevel 1%%e SET e=%%e
:: FOR %%e in (a p ) do If errorlevel a%%e SET e=%%e
:: SET i=0
:: FOR %%e in (0 1 2 3 4 5 6 7 8 9) do IF %%e==%e% SET e%i%=%e%
:: IF %i%==2 SET i=3
:: IF %i%==1 SET i=2
:: IF %i%==0 SET i=1
For different languages of the time format, see:
users.cybercity.dk/~bse26236/batutil/help/COUNTRN.HTM#$d$t
The "CHOICE/c;something; %0" Technique:
@%1 ECHO off
ECHO.:exit|%COMSPEC%/kPROMPT SET T=$_%0 goto:1 $t$_> %temp%.\~.bat
%temp%.\~.bat
:1
ECHO.;|CHOICE/c;%2%3%4%5%6%7%8%9; %0 goto:2> %temp%.\~.bat
%temp%.\~.bat
:2
SHIFT
FOR %%n in (0 1 2 3 4 5 6 7 8 9) do IF %%n==%1 SET T=%T%%1
IF not %2==]? GOTO 2
ECHO. time is %T%
SET T=
DEL %temp%.\~.bat
PS. Try put SET X=%T% before the FOR loop and
IF not %X%%1==%T% SET T=%T%-
after it.
Extracting
Additional notes can be found here:
http://users.cybercity.dk/~bse26236/tricks/tricks1.htm#extract
Input example: goodtime.avi sys.com
The modifications which I have added today, allows the user to press
the combination [Ctrl-Break] keys while "Extract.EXE" is running but
without interruption of the batch.
I.E.: I used "%COMSPEC%/c%0 %1 %5 %3 %4 %%f" instead of "CALL" along
with some few and minor additions.
The updated batch should now allows the user to be executing it from
a drive which media is write protected, (the attribute +R were set.)
:: Extract.bat for Win9X. Tested CDROM: Win95, Win98(1) and Win98(SE).
:: Hmmm -- A little problem about the PATH specification still remains
:: at line No. 10, ...(AUX %0 %0.bat) do IF... and may soon be solved.
:: A folder named c:\_extract maybe created & used for any extraction.
:: The Extract.bat file should be 4.096 bytes and exact 88 lines long:
@ ECHO off
%1 %2 FOR %%c in (CTTY" "NUL C:FIND.EXE CTTY" "CON) do %%c
IF errorlevel 2 GOTO C
SET P=%PATH%
PATH %PATH%;C:\WINDOWS\COMMAND
FOR %%c in (CTTY" "NUL C:FIND.EXE CTTY" "CON) do %%c
IF not errorlevel 2 FOR %%c in ("PATH %P%" "SET P=" GOTO:eof) do %%c
SET P=
:C
%2 FOR %%F in (AUX %0 %0.bat) do IF exist %%F SET D=%%F
%2 %D% goto:c ::
SET F= C:ATTRIB.EXE
IF not %F%) == C:ATTRIB.EXE) FOR %%c in (SET:F SET:D GOTO:eof) do %%c=
%F% %D%|C:FIND.EXE "R " >NUL
IF not A:\COMMAND.COM==%COMSPEC% IF errorlevel 1 %0 goto:-) - "%PATH%"
COPY %D% %temp%.\~~.bat >NUL
@ %temp%.\~~.bat goto :-) "%PATH%"
:-)
PATH %3
ECHO.-- Input filename of a file to be extracted from the Win Cabinet,
C:
ECHO e102'SET F='> %temp%.\~.tmp
FOR %%c in (w q) do ECHO %%c>> %temp%.\~.tmp
FC.EXE/n/Lb1 NUL CON|FIND.EXE "1">%temp%.\~.bat
DEBUG.EXE %temp%.\~.bat >NUL<%temp%.\~.tmp
ERASE %temp%.\~.tmp
FOR %%F in (CAL DE) do %%FL %temp%.\~.bat
ECHO.-- Hold [Shift] and put your Win9X source (CDROM) into the drive.
:input
CHOICE/n/cabcdefghijklmnopqrstuvwxyz -- Press drive letter of source:
IF errorlevel 27 FOR %%c in (SET:F SET:D CLS GOTO:eof) do %%c=
FOR %%D in (A B C D E F G H I J K L M) do IF errorlevel H%%D SET D=%%D
FOR %%D in (n o p q r s t u v w x y z) do IF errorlevel x%%D SET D=%%D
ECHO.
ECHO %F%|FIND.EXE ",">NUL
IF not errorlevel 1 %0 goto EasterEgg extract %D% %3 %F%
IF exist %D%:\win95\*.cab %0 goto ready %D% 95 extract %3 %2
IF exist %D%:\win98\*.cab %0 goto ready %D% 98 extract %3 %2
ECHO.-- Not found %D%:\Win9?\*.CAB-- Try again or press [Esc] to quit:
GOTO input
:ready
PATH %6
FOR %%c in (%3: CD) do %%c \win%4
%5.exe|FIND.EXE "/">NUL
IF errorlevel 1 ECHO.-- Not found %5.exe
IF errorlevel 1 FOR %%c in ( SET:F SET:D PAUSE CLS GOTO:EOF.) do %%c=
IF not exist c:\_%5\nul MD c:\_%5
IF not exist c:\_%5\win%4\nul MD c:\_%5\win%4
IF :-)==%7 ECHO.-- You should delete "%0" when the extraction is done.
IF :-)==%7 IF not exist "%COMSPEC%" ECHO.-- Give me COMSPEC: %COMSPEC%
IF :-)==%7 PAUSE,
FOR %%F in (%F%) do %COMSPEC%/c%0 %1 %5 %3 %4 %%F %6
FOR %%c in (CLS SET" F" SET" D") do %%c=
IF exist %windir%.\explorer.exe %windir%.\explorer.exe C:\_extract
IF not exist %windir%.\explorer.exe DIR /a-D/O/S /b/p C:\_extract
FOR %%F in (IF GOTO:EOF.) do %%F exist %temp%.\esf2 ERASE %temp%.\esf2
:extract
PATH %6
ECHO.-- %2ing "%5" of %3:\win%4\*.CAB to C:\_%2\win%4\%5
PAUSE
%2.exe /L c:\_%2\win%4 MINI.CAB %5
%2.exe /A /L c:\_%2\win%4 PRECOPY1.CAB %5
IF cdrom95==cdrom%4 %2.exe /A /L c:\_%2\win%4 WIN%4_02.CAB %5
IF cdrom95==cdrom%4 goto:!
%2.exe /L c:\_%2\win%4 CATALOG3.CAB %5
%2.exe /L c:\_%2\win%4 CHL99.CAB %5
%2.exe /A /L c:\_%2\win%4 BASE4.CAB %5
:! Other CAB files in Win98 are included with the above BASE.
IF exist C:\_%2\win%4\%5 GOTO eof
ECHO.-- The file do not exist in any cabinet: %3:\win%4\*.CAB
:eastereg
IF %2==EasterEgg FOR %%c in (ET:F ET:D HIFT) do S%%c=
IF %1==EasterEgg IF not exist C:\_%2\nul MKDIR C:\_%2
IF %1==EasterEgg PATH %4
C:CHOICE -- Do you want me to search "%5" on the entire drive %3: --
IF errorlevel 2 FOR %%c in (CLS GOTO) do %%c eof
ECHO.-- Wait several seconds...
REM>C:\_%2\!.txt
FOR %%c in (BREAK:ON DIR" %3:\%5/"s BREAK:OFF) do %%c>> C:\_%2\!.txt
C:FIND.EXE "//"/v/n< C:\_%2\!.txt | C:FIND.EXE "[8]" > NUL
IF not errorlevel 1 ECHO.-- YES! -- I found it. You can later read a
IF not errorlevel 1 ECHO. location in the file "C:\_extract\!.txt"
IF errorlevel 1 ECHO.-- Hmmm, the filename: "%5" seems not to exist.
IF errorlevel 1 DEL C:\_%2\!.txt
FOR %%c in (ECHO PAUSE CLS) do %%c.
IF %1==EasterEgg IF not (%windir%) == () %windir%.\explorer.exe C:\_%2
IF %1==EasterEgg IF (%windir%) == () DIR/a-d/o/w/p C:\_%2
:EOF by Benny Pedersen -- http://2dos.homepage.dk/ -- January 15, 2002
:: Extra notes:
:: Notis that if you have booted from a CDROM, then your A drive
:: will becomes drive B, if so, then you can execute Extract.BAT
:: on the floppy as B:EXTRACT and hit [Enter] at the DOS Prompt.
:: If you got the above version: (January 15, 2002), THEN IGNORE THIS:
:: Booted from a floppy and want to say A:EXTRACT from the DOS Prompt.
:: If your %COMSPEC% was A:\COMMAND.COM and A:\EXTRACT.BAT exist
:: on another floppy then be sure that the "A:\EXTRACT.BAT" file
:: is write protected. -- COMSPEC: In order to let the following
:: line work: FOR %%F in (%F%) do %COMSPEC%/c%0 %1 %5 %3 %4 %%F,
:: substitute the floppy disk (contents A:\EXTRACT.BAT) with the
:: boot disk, (when you see the prompting by A:\Extract.bat --).
:: Also remember something like this:
:: SET PATH=%PATH%;C:\WINDOWS\COMMAND
:: You can later delete the C:\~~.bat (if TEMP was set as C:\ ).
::
:: About line no 51:
:: The comma, which is added after the PAUSE as this:
:: IF :-)==%7 PAUSE,
:: can't be removed without an error (happens when %7 is blank).
:: What I try to say is that you should not remove one byte from
:: a file which is tested. If your copy isn't EXACT 4.096 bytes,
:: then you have just performed a bad copy of it.
Input and Redirection
@ECHO off
%1 %2 %0 CALL :: "in (F E D C B A 9 8 7 6 5 4 3 2 1 0) do" CON PRN %temp%.\~
%1 ECHO.-- Input two digits (hex),
%1 CHOICE/n/c.0123456789.......abcdef >NUL
%2 CHOICE/n/c.0123456789.......abcdef %8
%7 FOR %%e "%3" IF errorlevel }%%e %0 :: %1 %3 %4 %5 %6 %1 %8%%e %8%%e %8%%e
CHOICE/t2,99/c123 -- Choose a device, 1:%4, 2:%5 or the FILE 3: %6 --
FOR %%e in (2 3) do IF errorlevel %%e SHIFT
echo.
echo. Redirection
echo. of %8 (the selective hex value of the ASCII value of the character)
echo. to %4
ECHO.:EXIT|%COMSPEC%/kPROMPT n%4$_rcx$_6$_e0'%8 (' %8') '$_w0$_q|debug>NUL
echo., successfully executed.
Notis: If one would say 02 but said 2 (forgot the zero), then 2 followed by
a dot (2.) would be accepted as a valid input.
Benny Pedersen,
PS. You can (but isn't needed)
remove the above line no 2 to line no 1 and prefix with @ (see the 0C to PRN
solutions found in the Batch News Group along with that subject as heading).
(Line no 2 would be 77 characters long, which is ONE to much at my website).
@%1 %2 %0 CALL :: "in... snipped...
Links:
Devices
|