China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-19 23:55
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Share] The Oddities in Batch Programming DigestI View 30,932 Replies 50
Original Poster Posted 2004-01-11 00:00 ·  中国 山西 运城 联通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline



  People who have studied DOS have more or less heard of batch processing. It is compact and portable, and it is a system-level source code interpretation. It runs directly without compilation and linking, which has attracted many DOS enthusiasts and programmers. The participation of many people and the emergence of countless ingenious ideas have formed the "oddities" in batch processing programming. They are not designed simply to solve some "batch processing problems", but truly treat batch processing as a language to reflect its infinite creativity.

  The following are some batch processing programs I have collected. They may not be technically excellent, but they are definitely breakthroughs in conception. I will continuously update and improve this topic, and I also hope that everyone will work with me to complete this "oddity" collection.

  Index
======
1st floor: This topic
2nd floor: Game (Game):
1. TicTacToe (TicTacToe)
3rd floor: Mathematics (Math):
1. Random number (Random) generation, random matrix generation, total 2
2. 2K/XP expression calculation
4th floor: Clock (Clock):
1. Pause (Pause), delay (Delay), wait (Wait) or sleep (Sleep), total 5

  Declaration
======

  1. To maintain the structure of this post, please try not to reply here if you are only a comrade who praises and supports;
  2. Friends who have any questions and suggestions about some programs in this post, please visit the following topic
    http://www.cn-dos.net/forum/viewthread.php?tid=12388
  3. Friends who intend to recommend programs, please pay attention to the following selection criteria:
   (1) The functions implemented by the program have certain universality and innovation;
   (2) The program does not depend on any special or customized local environment (such as the path of the program);
   (3) The program does not use any third-party tools or software;
   (4) The program is best suitable for all Windows and DOS platforms. If there are special requirements, please note;
  4. This topic adopts the elimination system, that is, for codes that complete the same or similar functions, the one with the best writing quality will be adopted. When it is impossible to distinguish the advantages and disadvantages, or list them in one post at the same time, or integrate the excellent parts of the two to change them into new codes; the eliminated ones will either be listed in a separate topic or list the reference links.

 Update record
======
2004.06.20: Issue the " Oddities of Batch Processing Programming" topic and link with " Oddities of Batch Processing Programming"
2005.07.16: Update the prompt variable acquisition program on floor 7
2005.08.18: Modify floor 3 to the Mathematics (Math) topic and add random number and random array generation programs
2005.08.19: Modify floor 4 to the Clock (Clock) topic and add 5 "pause" programs
2005.09.11: The Mathematics (Math) topic on floor 3 adds "Batch Processing of 2K/XP Expression Calculation"


[ Last edited by willsort on 2005-9-11 at 13:35 ]
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 2 Posted 2004-01-11 00:00 ·  中国 山西 运城 联通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Program: TicTacToe (Three-in-a-Row, Tic-Tac-Toe, Draughts, Pick Up Sticks)
Author: M0eRtH
Original text: TicTacToe (a.k.a. Noughts''''''''n''''''''Crosses) BATch version 1.1
   http://users.volja.net/sarcasmus/M0/tictactoe/tttbat.html
Download: http://users.volja.net/sarcasmus/M0/tictactoe/tictactoebat.zip
Environment: 1. The program should run in an English command line environment;
   2. The program uses a large number of environment variables, and the size of the runtime environment space of the program should be modified;
   3. To run the program on WIN2K/XP, support for CHOICE is required;
Remarks:
  This is the first real game-like program I have seen written in batch processing. Although the program does not provide an AI opponent, its beautiful structure is still worthy of praise. The garbled characters in the main text are because the author used ANSI table characters.
Similar:
  Sherlock Holmes Q&A: http://dos.e-stone.cn/dosbbs/dispbbs.asp?boardID=6&ID=8272
  Maze in ZD Manor: http://zdland.xiloo.com/planets/psa.html

Main text:
@echo off
mode con cols=40 lines=25
cls
echo.
echo TicTacToe (a.k.a. Noughts''''''''n''''''''Crosses)
echo BATch Version 1.1
echo (c)2002 M0eRtH
echo.
echo Updates and more free stuff at
echo http://m0erth.cjb.net
echo.
echo The keys:
echo.
echo - X - - O -
echo.
echo 7 ?8 ?9 Q ?W ?E
echo 哪呐哪呐哪? 哪呐哪呐哪?
echo 4 ?5 ?6 A ?S ?D
echo 哪呐哪呐哪? 哪呐哪呐哪?
echo 1 ?2 ?3 Z/Y?X ?C
echo.
echo Ctrl+R = Reset game Ctrl+Q = Quit
echo.
echo Note:
echo X, make sure the NumLock is ON. ;-)
echo.
pause

set a1=-
set a2=-
set a3=-
set b1=-
set b2=-
set b3=-
set c1=-
set c2=-
set c3=-
set turn=X
set win=-
set result=-
set scoreX=-
set scoreO=-
set games=-
set maxgames=-++++++++++++++++++++

:draw
cls
echo.
echo TicTacToe (a.k.a. Noughts''''''''n''''''''Crosses)
echo BATch Version 1.1
echo (c)2002 M0eRtH
echo.
echo Score
echo X:%scoreX%
echo O:%scoreO%
echo.
echo %a1% ?%a2% ?%a3%
echo 哪呐哪呐哪?
echo %b1% ?%b2% ?%b3%
echo 哪呐哪呐哪?
echo %c1% ?%c2% ?%c3%
echo.

:chkWin
set result=%a1%%a2%%a3%
if %result%==XXX goto XWon
if %result%==OOO goto OWon
set result=%b1%%b2%%b3%
if %result%==XXX goto XWon
if %result%==OOO goto OWon
set result=%c1%%c2%%c3%
if %result%==XXX goto XWon
if %result%==OOO goto OWon
set result=%a1%%b1%%c1%
if %result%==XXX goto XWon
if %result%==OOO goto OWon
set result=%a2%%b2%%c2%
if %result%==XXX goto XWon
if %result%==OOO goto OWon
set result=%a3%%b3%%c3%
if %result%==XXX goto XWon
if %result%==OOO goto OWon
set result=%a1%%b2%%c3%
if %result%==XXX goto XWon
if %result%==OOO goto OWon
set result=%c1%%b2%%a3%
if %result%==XXX goto XWon
if %result%==OOO goto OWon

:getKeys
echo %turn%''''''''s turn
choice /c:789456123qweasdzyxc /n :
if errorlevel 21 goto reset
if errorlevel 20 goto quit
if errorlevel 19 goto setOC3
if errorlevel 18 goto setOC2
if errorlevel 17 goto setOC1
if errorlevel 16 goto setOC1
if errorlevel 15 goto setOB3
if errorlevel 14 goto setOB2
if errorlevel 13 goto setOB1
if errorlevel 12 goto setOA3
if errorlevel 11 goto setOA2
if errorlevel 10 goto setOA1
if errorlevel 9 goto setXC3
if errorlevel 8 goto setXC2
if errorlevel 7 goto setXC1
if errorlevel 6 goto setXB3
if errorlevel 5 goto setXB2
if errorlevel 4 goto setXB1
if errorlevel 3 goto setXA3
if errorlevel 2 goto setXA2
if errorlevel 1 goto setXA1
goto draw

:reset
set a1=-
set a2=-
set a3=-
set b1=-
set b2=-
set b3=-
set c1=-
set c2=-
set c3=-
goto draw

:setXA1
if not %a1%==- goto draw
if %turn%==O goto draw
set a1=X
goto changeTurn
:setXA2
if not %a2%==- goto draw
if %turn%==O goto draw
set a2=X
goto changeTurn
:setXA3
if not %a3%==- goto draw
if %turn%==O goto draw
set a3=X
goto changeTurn

:setXB1
if not %b1%==- goto draw
if %turn%==O goto draw
set b1=X
goto changeTurn
:setXB2
if not %b2%==- goto draw
if %turn%==O goto draw
set b2=X
goto changeTurn
:setXB3
if not %b3%==- goto draw
if %turn%==O goto draw
set b3=X
goto changeTurn

:setXC1
if not %c1%==- goto draw
if %turn%==O goto draw
set c1=X
goto changeTurn
:setXC2
if not %c2%==- goto draw
if %turn%==O goto draw
set c2=X
goto changeTurn
:setXC3
if not %c3%==- goto draw
if %turn%==O goto draw
set c3=X
goto changeTurn


:setOA1
if not %a1%==- goto draw
if %turn%==X goto draw
set a1=O
goto changeTurn
:setOA2
if not %a2%==- goto draw
if %turn%==X goto draw
set a2=O
goto changeTurn
:setOA3
if not %a3%==- goto draw
if %turn%==X goto draw
set a3=O
goto changeTurn

:setOB1
if not %b1%==- goto draw
if %turn%==X goto draw
set b1=O
goto changeTurn
:setOB2
if not %b2%==- goto draw
if %turn%==X goto draw
set b2=O
goto changeTurn
:setOB3
if not %b3%==- goto draw
if %turn%==X goto draw
set b3=O
goto changeTurn

:setOC1
if not %c1%==- goto draw
if %turn%==X goto draw
set c1=O
goto changeTurn
:setOC2
if not %c2%==- goto draw
if %turn%==X goto draw
set c2=O
goto changeTurn
:setOC3
if not %c3%==- goto draw
if %turn%==X goto draw
set c3=O
goto changeTurn


:changeTurn
if %turn%==X goto setTurnO
set turn=X
goto draw
:setTurnO
set turn=O
goto draw


:XWon
echo.
echo - X won! -
pause
set scoreX=%scoreX%+
set games=%games%+
if %games%==%maxgames% goto quit
goto reset

:OWon
echo.
echo - O won! -
pause
set scoreO=%scoreO%+
set games=%games%+
if %games%==%maxgames% goto quit
goto reset

:quit
mode con cols=80 lines=25
echo.
echo TicTacToe (a.k.a. Noughts''''''''n''''''''Crosses)
echo BATch Version 1.1
echo (c)2002 M0eRtH
echo.
echo Updates and more free stuff at
echo http://m0erth.cjb.net
echo.
echo.
echo X scored: %scoreX%
echo O scored: %scoreO%
echo.
set a1=
set a2=
set a3=
set b1=
set b2=
set b3=
set c1=
set c2=
set c3=
set turn=
set win=
set result=
set scoreX=
set scoreO=
set games=
set maxgames=
pause







※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 3 Posted 2004-01-12 00:00 ·  中国 山东 烟台 联通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
### Mathematics - Random

1) Random Number Generator: After running, it can generate a random integer from 00 to 99 and save it in the environment variable %_random%.

If you want to generate more complex random numbers, you can also modify this program. For example, combining two generated random numbers can get a random number from 0000 to 9999; adding a decimal point in front of the random number can get a random decimal from 0.00 to 0.99; removing the first underscore in prompt _$T$_:: can get a random number from 0 to 9; and using debug can remove the prefix 0 of some random numbers. According to the above methods, you can combine to get random numbers in any form.

:: GenARnd.Bat - Generate a random integer (00~99)
:: Will Sort - 12:06 2005-8-18 - V2 - MSDOS7.10/CMD@WinXP/MSDOS6.22
@echo off
echo exit|%comspec% /k prompt _$T$_::> _GenARnd.bat
echo e 100 "set _random=">_GenARnd.asd
for %%s in (w q) do echo %%s>>_GenARnd.asd
debug _GenARnd.bat < _GenARnd.asd > nul
call _GenARnd.bat
for %%f in (_GenARnd*.*) do del %%f
if not "%_random%"=="" if not == echo Random number : %_random%
:End


2) Random Array Generator: After running, it will generate a random probability distribution matrix diagram.

This diagram has 24 rows and 63 columns, composed of the characters "-" (false) and "o" (true). Every three rows from top to bottom form a group, and the distribution probability of o shows a decreasing trend. Among them, the left graph in the matrix is the distribution of true and false sequences, and the right graph is the comparison of the number of true and false.

:: RndArray.bat - Generate a serial of random numbers(- or o)
:: Will Sort - 2004/11/24
@echo off
if "%1"==":" goto %2

set no=
set num=0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9

:loop
set no=I%no%
set line=
set -=
set o=
for %%c in (%num%) do call %0 : random %no%
echo %line% : %-%%o%
set line=
set -=
set o=
for %%c in (%num%) do call %0 : random %no%
echo %line% : %-%%o%
set line=
set -=
set o=
for %%c in (%num%) do call %0 : random %no%
echo %line% : %-%%o%
if not == goto loop

:quit
del _Random.tmp
for %%e in (- o no num line) do set %%e=
goto end

:random
echo. | time > _Random.tmp
::echo exit | %comspec% /k prompt $T>_Random.tmp
goto %3

find ".0"<_Random.tmp>nul
if not errorlevel 1 goto true
:I
find ".3"<_Random.tmp>nul
if not errorlevel 1 goto true
:II
find ".6"<_Random.tmp>nul
if not errorlevel 1 goto true
:III
find ".9"<_Random.tmp>nul
if not errorlevel 1 goto true
:IIII
find ".2"<_Random.tmp>nul
if not errorlevel 1 goto true
:IIIII
find ".5"<_Random.tmp>nul
if not errorlevel 1 goto true
:IIIIII
find ".8"<_Random.tmp>nul
if not errorlevel 1 goto true
:IIIIIII
find ".1"<_Random.tmp>nul
if not errorlevel 1 goto true
:IIIIIIII
find ".4"<_Random.tmp>nul
if not errorlevel 1 goto true
find ".7"<_Random.tmp>nul
if not errorlevel 1 goto true
::del _Random.tmp

:false
set line=%line%-
set -=-%-%
goto end

:true
set line=%line%o
set o=o%o%
goto end

:end


### Mathematics - Expressions

1) 2K/XP Expression Calculation Batch Processing, originally created and maintained by Brglng. When reposting, the document part in the program is simplified. You can check the complete code and document through the following link.

{16534} 2K/XP Expression Calculation Batch Processing
http://www.cn-dos.net/forum/viewthread.php?tid=16534

:: Eval.cmd - 2K/XP Expression Calculation Batch Processing
:: Brglng - 2005.8.31
@echo off
setlocal
if /i "%1"=="/A" if "%2"=="" echo A file path must be specified!& goto end
if /i not "%1"=="/A" if /i not "%1"=="/N" if not "%1"=="" goto EvalArgument

echo Please enter an expression (enter "Q" to quit) & goto inputExpr

:EvalArgument
set /a EvalExpr="%1"
if "%EvalExpr%"=="" echo Incorrect expression input! & goto end
echo %1=%EvalExpr%
if "%2"=="" goto end
echo %1=%EvalExpr% >>"%2"
echo The formula and calculation result have been stored in "%2"!
goto end

:inputExpr
set Expr=
set EvalExpr=
set /p Expr=>
if "%Expr%"=="" goto inputExpr
if /i "%Expr%"=="Q" goto end
set /a EvalExpr="%Expr%"
if "%EvalExpr%"=="" echo Incorrect input! & goto inputExpr
echo The calculation result is: %EvalExpr%
if /i "%1"=="/A" goto autosave
if /i "%1"=="/N" goto inputExpr

:if_save
set SaveEval=
set /p SaveEval=Do you want to store the expression and calculation result in a file ?
if /i "%SaveEval%"=="Y" goto save
if /i "%SaveEval%"=="N" goto inputExpr
goto if_save

:save
set /p SaveEvalPath=Please enter the file path and file name (such as C:\Windows\file.txt. If you only enter the file name, it will be automatically stored in the current folder. Leave it blank for the last entered path):
echo "%Expr%"=%EvalExpr% >>"%SaveEvalPath%"
echo The expression and calculation result have been stored in "%SaveEvalPath%"!
goto inputExpr

:autosave
echo "%Expr%"=%EvalExpr% >>"%2"
goto inputExpr

:end


[ Last edited by willsort on 2005-9-11 at 13:37 ]
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 4 Posted 2004-01-12 00:00 ·  中国 山东 烟台 联通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
1、Pause, Delay, Wait, Sleep

1) for+set+if, with a time precision of 0.01 seconds, applicable platforms: WinNT/2K/XP/2003.

Use for to parse the variable %time% and store it as two time points %start% and %now%, then use set /a to calculate the time difference between the two time points, and finally use if to judge whether the time difference has reached the set pause time.

@echo off
setlocal enableextensions
echo %time%
call rocDelay 200
echo %time%
goto :EOF

rocDelay delayMSec_
setlocal enableextensions
for /f "tokens=1-4 delims=:. " %%h in ("%time%" do set start_=%%h%%i%%j%%k
:_procwaitloop
for /f "tokens=1-4 delims=:. " %%h in ("%time%" do set now_=%%h%%i%%j%%k
set /a diff_=%now_%-%start_%
if %diff_% LSS %1 goto _procwaitloop
endlocal & goto :EOF


2) The sleep function in VBS scripts, with a time precision of 0.001 seconds, applicable platforms: Win9x/WinNT series.

Dynamically create a VBS script that calls the sleep() function, and then use the command-line version of the Windows Script Host, cscript, to call it.

@echo off & setlocal enableextensions enabledelayedexpansion
echo WScript.Sleep 2000 > %temp%\tmp$$$.vbs
echo %time%
cscript //nologo %temp%\tmp$$$.vbs
echo %time%
for %%f in (%temp%\tmp$$$.vbs) do if exist %%f del %%f
endlocal & goto :EOF


3) The message sending interval of ping, with a time precision of 1 second, applicable platforms: Win9x/WinNT series.

Your Windows system needs to have the TCP/IP protocol of the network card normally installed. There are two schemes. Scheme two is not recommended. See the theme The Oddities of Batch Programming on floors 12 and 13:

(1) Use the interval time between two ping message sends. When ping sends multiple messages, after getting the response of the previous message, it will wait for 1 second before sending the next message. And this response time varies due to the model, system, and network configuration. Among them, the local loopback address 127.0.0.1 is relatively constant because it responds immediately. Other addresses mostly have significant differences. This method needs to wait a longer time. It is to specify the number of messages sent as one more than the waiting time, because the first message is not waited for. The IP address must be 127.0.0.1. The program to wait for 2 seconds is as follows:

:: According to the tree-planting principle, the number after n is one more than the pause seconds
ping -n 3 127.0.0.1>nul


(2) Use the maximum waiting time of ping. ping sends an "Internet Control Message Protocol (ICMP)" echo request message to 0.0.0.1. Because 0.0.0.1 is an IP address that cannot respond to ping requests, by default, ping will wait for a certain maximum response time - it stops waiting after 4 seconds, and -w can change this maximum response time for each message send. And if the IP address is changed to 127.0.0.1 or other IP addresses with very short response times that respond immediately, then -w loses its effect because the waiting time for each send will not reach the maximum response time, and the delay will be shortened. This method needs to wait a longer time. You can directly use -w to specify, but you need to subtract a certain sending delay. This delay needs to be measured in advance, otherwise there will be an error of less than 1 second; and the IP address must be an address that does not respond to requests. The program to wait for 2 seconds is as follows:
ping -n 2 -w 500 0.0.0.1>nul


4) The default selection waiting function of choice, with a time precision of 1 second, applicable platforms: MS-DOS/Win9x/WinNT series.

/t:y,2 sets the default selection character to y, the waiting time is 2 seconds, /n prohibits the prompt from appearing on the command line, and the role of "rem|" is to prohibit choice from accepting key presses from the keyboard, so that the pause will not be accidentally terminated by pressing y or other keys.

rem|choice /t:y,2 /n >nul


5) ASCII assembly code, with a delay precision of 0.001 seconds, applicable platforms: MS-DOS/Win9x/WinNT.

German Herbert Kleebauer gave a general solution. By indirectly generating a sleep.exe program through an ASCII assembler to achieve delay. This program is divided into DOS and Win modules, which respectively call DOS system interrupt services and Windows APIs.

:: Sleep.bat - Sleep/Delay/Wait n seconds
:: Herbert Kleebauer(Germany) - 2005/05/29
:: Modified by Will Sort - 2005/06/02, 07-25
@echo off
echo q | debug>nul
echo Bj@jzh`0X-`/PPPPPPa(DE(DM(DO(Dh(Ls(Lu(LX(LeZRR]EEEUYRX2Dx=>sleep.com
echo 0DxFP,0Xx.t0P,=XtGsB4o@$?PIyU WwX0GwUY Wv;ovBX2Gv0ExGIuht6>>sleep.com
echo T}{z~~@GwkBG@OEKcUt`~}@MqqBsy?seHB~_Phxr?@zAB`LrPEyoDt@Cj?>>sleep.com
echo pky_jN@QEKpEt@ij?jySjN@REKpEt@jj?jyGjN@SEKkjtlGuNw?p@pjirz>>sleep.com
echo LFvAURQ?OYLTQ@@?~QCoOL~RDU@?aU?@{QOq?@}IKuNWpe~FpeQFwH?Vkk>>sleep.com
echo _GSqoCvH{OjeOSeIQRmA@KnEFB?p??mcjNne~B?M??QhetLBgBPHexh@e=>>sleep.com
echo EsOgwTLbLK?sFU`?LDOD@@K@xO?SUudA?_FKJ@N?KD@?UA??O}HCQOQ??R>>sleep.com
echo _OQOL?CLA?CEU?_FU?UAQ?UBD?LOC?ORO?UOL?UOD?OOI?UgL?LOR@YUO?>>sleep.com
echo dsmSQswDOR











[ Last edited by willsort on 2005-12-4 at 21:37 ]
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 5 Posted 2004-01-12 00:00 ·  中国 山东 烟台 联通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Below is a program for drawing in character mode. The original text came from the DOS board of NetEase Guangzhou.
http://fe2.gz.163.com/cgi/readsrh?b=DOS&t=15763&i=15763&al=5&n=0&l=40&back=2&st=0&kw=MAP

This program works in a very crude way, but it already has some basic functions, such as drawing, erasing, changing the brush character, saving and extracting character drawings, backing up and restoring character drawings, making character drawings executable, and so on. The program uses the support functions of ANSI.SYS, so the box character after ECHO is actually the symbol with ASCII code 27. Under DOS, you can enter this character in EDIT by pressing CTRL+P and then ESC.

------------------------------------

@ECHO OFF
:START
IF NOT == GOTO MAP%1
IF == GOTO MAPHELP
CHOICE Initizing, Please waiting../C:. /T:.,1 /N
IF == GOTO MAPRESTORE
IF == GOTO MAPEXTRACT
IF == GOTO MAPTRYSAVE

MEM /C|FIND "ANSI">NUL
IF ERRORLEVEL 1 GOTO MAPERR1

IF == GOTO MAPINIT
IF == GOTO MAPERR2
IF == IF NOT == IF NOT == SET $F=%2
IF == GOTO MAPSTART

IF NOT EXIST %2.MAP GOTO MAPERR5
FIND "




== GOTO MAPVIEW
IF == GOTO MAPLOAD
IF == GOTO MAPMAKE
:MAPINIT
CLS
SET $F=?
SET PRE=C
GOTO MAPSTART

:MAPHELP
ECHO.
ECHO Use: Draw a map with painter of characterS, and save to map file.
ECHO Usage: %0 option: parameter
ECHO Option:
ECHO L Load map file from the specified location.
ECHO M Make map file to selfexec map program.
ECHO E Extract selfexec map to map file.
ECHO T Try save map file from temporary location.
ECHO R Restore the map backuped map file.
ECHO V View the map file parameter specifle.
ECHO C define painter with Character parameter specifle.
ECHO.
CHOICE View guide of draw:
IF ERRORLEVEL 2 GOTO MAPEND
ECHO.
ECHO All operation control by keyboard keys.
ECHO.
ECHO Key: Use:
ECHO 1 Left and down ----)
ECHO 2 Down )
ECHO 3 Right and down )
ECHO 4 Left )---Painter Move keys
ECHO 6 Right )
ECHO 7 Left and up )
ECHO 8 Up )
ECHO 9 Right and up------)
ECHO 5 painter
ECHO 0(Ins) change to draw state
ECHO .(Del) change to delete state
ECHO.
GOTO MAPEND

:MAPERR1
ECHO.
ECHO Error 1 in %0: Not continue for not load ANSI.
ECHO.
GOTO MAPEND
:MAPERR2
ECHO.
ECHO Error 2 in %0: Not specified second parameter.
ECHO.
GOTO MAPEND
:MAPERR3
ECHO.
ECHO Error 3 in %0: False map file.
ECHO.
GOTO MAPEND
:MAPERR4
ECHO.
ECHO Error 4 in %0: Not accomplish map file.
ECHO.
GOTO MAPEND
:MAPERR5
ECHO.
ECHO Error 5 in %0: Not exist map file.
ECHO.
GOTO MAPEND
:MAPERR6
ECHO.
ECHO Error 6 in %0: Not backup map file.
ECHO.
GOTO MAPEND
:MAPERR7
ECHO.
ECHO Error 7 in %0: Not make selfexec map program.
ECHO.
GOTO MAPEND
:MAPERR8
ECHO.
ECHO Error 8 in %0: Not correctly pattern selfexec map program.
ECHO.
GOTO MAPEND
:MAPERR9
ECHO.
ECHO Error 9 in %0: Can''''t view map file.
ECHO.
GOTO MAPEND
:MAPERR10
ECHO.
ECHO Error 10 in %0: enviroment parameter PRE is null.

::MAPPICK
IF EXIST %2.MAP CHOICE Modify this map file
IF ERRORLEVEL 2 GOTO MAPEND
ECHO @CLS>PAINTER.BAT
ECHO @SET $F=%%1>>PAINTER.BAT
ECHO @%0 START %2 /S>>PAINTER.BAT
ECHO Please choose painter of character with style (PAINTER=char).
PROMPT 
GOTO MAPEND
:MAPSAVEPRE
ECHO @ECHO OFF>>SAVEFILE.BAT
IF == ECHO IF NOT == %0 SAVE %%1 /G>>SAVEFILE.BAT
IF == ECHO IF NOT == %0 SAVE %%1 /G %2>>SAVEFILE.BAT
ECHO ECHO Please input save path again:>>SAVEFILE.BAT
ECHO Please save file and path with (SAVEFILE=path\file) style:
PROMPT 
GOTO MAPEND
:MAPSAVE
IF NOT EXIST %2.MAP GOTO MAPSSUF
IF NOT == GOTO MAPSSUF
CHOICE Map name exist, rename
IF ERRORLEVEL 2 GOTO MAPSSUF
ECHO Please input save path again:
GOTO MAPEND
:MAPSSUF
PROMPT $P$G
IF EXIST SAVEFILE.BAT DEL SAVEFILE.BAT
IF == COPY %4.MAP %4.MBK /Y>NUL
COPY %TEMP%\TEMP.MP$ %2.MAP /Y>NUL
DEL %TEMP%\TEMP.MP$
GOTO MAPEND
:MAPLOAD
COPY %2.MAP %TEMP%\%2.BAT>NUL
ECHO @ECHO OFF>PAINTER.BAT
ECHO CLS>>PAINTER.BAT
ECHO IF == GOTO PEND>>PAINTER.BAT
ECHO SET $F=%%1>>PAINTER.BAT
ECHO CALL %0 KEYON # /G>>PAINTER.BAT
ECHO CALL %TEMP%\%2.BAT>>PAINTER.BAT
ECHO %0 START %2 /L>>PAINTER.BAT
ECHO END>>PAINTER.BAT
ECHO Please choose painter of character with style (PAINTER=char).
PROMPT 
GOTO MAPEND
:MAPVIEW
IF NOT EXIST %2.MAP GOTO MAPERR5
COPY %2.MAP %TEMP%\%2.BAT>NUL
CLS
CALL %TEMP%\%2.BAT
ECHO 









































































































== CALL %0 KEYON # /G
IF == GOTO MAPEDIT
IF == GOTO MAPEDIT
:MAPLENG
SET $M=
SET $CN=





== GOTO MAPEDIT
SET $A$=%$B$%
SET $DN=%$DN%












== GOTO MAPNEW
COPY %2.MAP %TEMP%\TEMP.MP$ /Y>NUL
SET $SN=%$LN%
SET $LN=
SET $SF=%$F%
SET $F=
IF == GOTO MAPLINE
IF == GOTO MAPPIPE
GOTO MAPCHAR
:MAPNEW
IF EXIST %TEMP%\TEMP.MP$ DEL %TEMP%\TEMP.MP$
ECHO 


== GOTO MAPLINE
IF == GOTO MAPPIPE
GOTO MAPCHAR

:MAPCHAR
ECHO 
















== GOTO MAPCOVER
SET $LN=%$SN%
SET $SN=
SET $F=%$SF%
SET $SF=
GOTO MAPCHAR
:MAPCOVER
SET $SN=%$LN%
SET $LN=
SET $SF=%$F%
SET $F=
GOTO MAPCHAR
:MAPCINS
IF == GOTO MAPCOINS
IF NOT == GOTO MAPCHAR
SET $F=%$T%
SET $T=
GOTO MAPCHAR
:MAPCOINS
IF NOT == GOTO MAPCHAR
SET $SF=%$T%
SET $T=
GOTO MAPCHAR
:MAPCDEL
IF == GOTO MAPCODEL
IF == GOTO MAPCHAR
SET $T=%$F%
SET $F=%$M%
GOTO MAPCHAR
:MAPCODEL
IF == GOTO MAPCHAR
SET $T=%$SF%
SET $SF=%$M%
GOTO MAPCHAR

:MAPCRGDW
ECHO 








































































































== GOTO MAPLOVER
SET $F=%$SF%
SET $SF=
GOTO MAPLINE
:MAPLOVER
SET $SF=%$F%
SET $F=
GOTO MAPLINE
:MAPLINS
IF == GOTO MAPLOINS
IF NOT == GOTO MAPLINE
SET $F=%$T%
SET $T=
GOTO MAPLINE
:MAPLOINS
IF NOT == GOTO MAPLINE
SET $SF=%$T%
SET $T=
GOTO MAPLINE
:MAPLDEL
IF == GOTO MAPLODEL
IF == GOTO MAPLINE
SET $T=%$F%
SET $F=%$M%
GOTO MAPLINE
:MAPLODEL
IF == GOTO MAPLINE
SET $T=%$SF%
SET $SF=%$M%
GOTO MAPLINE

:MAPLRIGHT
SET $BF=?
IF == SET $BF=?
IF == SET $BF=?
IF == SET $F=%$BF%
ECHO 








== SET $BF=?
IF == SET $BF=?
IF == SET $F=%$BF%
ECHO 








== SET $BF=?
IF == SET $BF=?
IF == SET $F=%$BF%
ECHO 








== SET $BF=?
IF == SET $BF=?
IF == SET $F=%$BF%
ECHO 








































































== GOTO MAPPOVER
SET $F=%$SF%
SET $SF=
GOTO MAPPIPE
:MAPPOVER
SET $SF=%$F%
SET $F=
GOTO MAPPIPE
:MAPPINS
IF == GOTO MAPPOINS
IF NOT == GOTO MAPPIPE
SET $F=%$T%
SET $T=
GOTO MAPPIPE
:MAPPOINS
IF NOT == GOTO MAPPIPE
SET $SF=%$T%
SET $T=
GOTO MAPPIPE
:MAPPDEL
IF == GOTO MAPPODEL
IF == GOTO MAPPIPE
SET $T=%$F%
SET $F=%$M%
GOTO MAPPIPE
:MAPPODEL
IF == GOTO MAPPIPE
SET $T=%$SF%
SET $SF=%$M%
GOTO MAPPIPE

:MAPPRIGHT
SET $BF=?
IF == SET $BF=?
IF == SET $BF=?
IF == SET $F=%$BF%
ECHO 








== SET $BF=?
IF == SET $BF=?
IF == SET $F=%$BF%
ECHO 








== SET $BF=?
IF == SET $BF=?
IF == SET $F=%$BF%
ECHO 








== SET $BF=?
IF == SET $BF=?
IF == SET $F=%$BF%
ECHO 





































※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 6 Posted 2004-01-12 00:00 ·  中国 山东 烟台 联通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
The following is a program to draw a character dog on the command line prompt. The original text is from the DOS version of NetEase Beijing Station.
http://fe4.bj.163.com/cgi/readsrh?b=DOS&t=38819&i=38819&al=5&n=0&l=40&back=2&st=0&kw=DOS%B5%C4%CD%BC%D0%CE

The program requires ANSI support. There are defects in it, and the solution can be found by querying the original website.

--------------------------------------

@PROMPT { (\__ }
ECHO 

















※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 7 Posted 2004-01-12 00:00 ·  中国 山东 烟台 联通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Here is the translation:

Here is a program to obtain PROMPT system status data. The original text is from the DOS version of NetEase Guangzhou Station.
http://fe2.gz.163.com/cgi/readsrh?b=DOS&t=25501&i=25609&al=5&n=0&l=40&back=2&st=1&kw=willsort

When running, add the variable name where the data is stored and the PROMPT - corresponding variable name, for example:
getvar curver $v
The extractable system status data includes:

$T Current time
$D Current date
$P Current drive and path
$V System version number
$N Current drive

------------------------------------

::getvar.bat
@if == prompt set %2=%3
@if == goto end
@echo off
%comspec% /c %0 invoke %1 %2>tt.bat
call tt

:end

------------------------------------
Update on 2005.07.16:
:: GetVar.bat - Get from 'PROMPT' text to environment variable 
:: Will Sort - 10:29 2005-7-16 - CMD@XP/COMMAND@Win98/MSDOS6.22
@echo off
echo exit | %comspec% /k prompt set %1=%2$_:: > _GetVar.bat
call _GetVar.bat
for %%f in (_GetVar*.*) do del %%f





[ Last edited by willsort on 2005-10-29 at 12:36 ]
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 8 Posted 2004-01-12 00:00 ·  中国 山东 烟台 联通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Here is the translation:


The following is a timer program. The original text comes from the DOS version of NetEase Guangzhou Station.
http://fe2.gz.163.com/cgi/readsrh?b=DOS&t=13486&i=15375&al=5&n=40&l=40&back=2&st=1&kw=willsort

The CURRENT.BAT in the program can be replaced with the content you need to execute. The time of the FIND sentence can be set according to your needs, and can also be replaced with the parameter %1. It can also be changed to TIME to DATE to complete the function of regular execution.

------------------------------

::CURRENT.BAT
@echo off
echo Haha, it's the time to go!!

::TIMER.BAT
@echo off
:start
echo.|time|find "10:30:00">run.bat
choice /c:y /t:y,59 /n>nul
call run.bat
goto start
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 9 Posted 2004-01-12 00:00 ·  中国 山东 烟台 联通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
1、Sharing
1)Delete the default shares of the win2k/xp system

Original text from "Batch Processing Concise Tutorial"
http://www.realhack.org/article/articleshow.asp?ArticleID=954

@echo preparing to delete all the default shares. when ready press any key.
@pause
@echo off
:Rem check parameters if null show usage.
if {%1}=={} goto :Usage
:Rem code start.
echo.
echo ------------------------------------------------------
echo.
echo Now deleting all the default shares.
echo.
net share %1$ /delete
net share %2$ /delete
net share %3$ /delete
net share %4$ /delete
net share %5$ /delete
net share %6$ /delete
net share %7$ /delete
net share %8$ /delete
net share %9$ /delete
net stop Server
net start Server
echo.
echo All the shares have been deleteed
echo.
echo ------------------------------------------------------
echo.
echo Now modify the registry to change the system default properties.
echo.
echo Now creating the registry file
echo Windows Registry Editor Version 5.00> c:\delshare.reg
echo >> c:\delshare.reg
echo "AutoShareWks"=dword:00000000>> c:\delshare.reg
echo "AutoShareServer"=dword:00000000>> c:\delshare.reg
echo Nowing using the registry file to chang the system default properties.
regedit /s c:\delshare.reg
echo Deleting the temprotarily files.
del c:\delshare.reg
goto :END

:Usage
echo.
echo ------------------------------------------------------
echo.
echo ☆ A example for batch file ☆
echo ☆ ☆
echo.
echo Author:Ex4rch
echo Mail:Ex4rch@hotmail.com QQ:1672602
echo.
echo Error:Not enough parameters
echo.
echo ☆ Please enter the share disk you wanna delete ☆
echo.
echo For instance,to delete the default shares:
echo delshare c d e ipc admin print
echo.
echo If the disklable is not as C: D: E: ,Please chang it youself.
echo.
echo example:
echo If locak disklable are C: D: E: X: Y: Z: ,you should chang the command into :
echo delshare c d e x y z ipc admin print
echo.
echo *** you can delete nine shares once in a useing ***
echo.
echo ------------------------------------------------------
goto :EOF
:END
echo.
echo ------------------------------------------------------
echo.
echo OK,delshare.bat has deleted all the share you assigned.
echo.Any questions ,feel free to mail to Ex4rch@hotmail.com.
echo
echo.
echo ------------------------------------------------------
echo.
:EOF
echo end of the batch file


2)Program to PING all IPs in a certain segment

Original text from the DOS version of NetEase Beijing Station.
http://fe4.bj.163.com/cgi/readsrh?b=DOS&t=94897&i=96159&al=5&n=0&l=40&back=2&st=1&kw=willsort

Enter a.bat 0 1 2 3 4 5 6 7 8 9 at the command line, and it will display all IP addresses in a certain segment 192.168.1.0 - 192.168.1.99. Just change echo to ping. The choice and if statements are for waiting for the user to judge whether to continue and can be deleted, but it will be more troublesome to interrupt the program.


@echo off
:redo
if "%1" == "" goto end
for %%a in (0,1,2,3,4,5,6,7,8,9) do echo 192.168.1.%1%%a
choice continue
if errorlevel 2 goto end
shift
goto redo
:end


[ Last edited by willsort on 2005-8-19 at 17:17 ]
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 10 Posted 2004-01-12 00:00 ·  中国 山东 烟台 联通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Here is the translation:


The following is a program to modify the update date of a file. The original text comes from the DOS version of NetEase Beijing Station.
http://fe4.bj.163.com/cgi/readsrh?b=DOS&t=85861&i=85878&al=5&n=0&l=40&back=2&st=1&kw=willsort

There are several errors in the original code. The following is the corrected version.

--------------------------------------

@echo off
rem Save the system time
echo.|date>sysdate.bat
echo.|time>systime.bat
rem Modify the system time to the specified time, the date is parameter one, the time is parameter two, and the file name is parameter three
date %1
time %2
rem Modify the time of the file
copy %3+,,>nul
rem Restore the system time
echo date %%4>current.bat
call sysdate
echo time %%3>current.bat
call systime
rem Program execution completed
echo Success.
del systime.bat
del sysdate.bat
del current.bat
echo on



※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 11 Posted 2004-01-12 00:00 ·  中国 山东 烟台 联通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
The following is a file traversal program, originally from the DOS version of NetEase Guangzhou Station.
http://fe2.gz.163.com/cgi/readsrh?b=DOS&t=21718&i=21882&al=5&n=0&l=40&back=2&st=1&kw=willsort

The original text uses two external programs, VARSET and LMOD, may be downloaded from this station or the new DOS era

@echo off
rem ///////////////////Search all *.txt files in all directories///////////////////

rem Find *.txt in the current directory (root directory)
for %%a in (*.txt) do type %%a

rem The following is to find all *.txt in all subdirectories of the current directory (root directory)

set i=1
set j=1
set filenum=0
set dirnum=0

varset root=FULL of . >temp.bat
call temp.bat

varset rootdir=string(3) %root% >temp.bat
call temp.bat

dir /ad /b /s >temp.txt

varset dirnum=lines temp.txt >temp.bat
call temp.bat

:loop1

type %root%\temp.txt | %root%\LMOD /L%i% set curdir= >%root%\temp.bat
call %root%\temp.bat

varset curdir=string(3) %curdir% >%root%\temp.bat
call %root%\temp.bat

cd %curdir%
echo %curdir%
set j=1
:loop2
%root%\varset filenum=files *.txt >%root%\temp.bat
call %root%\temp.bat
if %filenum%==0 goto end2

dir *.txt /b | %root%\LMOD /L%j% set curfile= >%root%\temp.bat
call %root%\temp.bat

type %curfile%

if %j%==%filenum% goto end2

%root%\varset j=%j%+1 >%root%\temp.bat
call %root%\temp.bat
goto loop2
:end2
cd %rootdir%

if %i%==%dirnum% goto end1

%root%\varset i=%i%+1 >%root%\temp.bat
call %root%\temp.bat
goto loop1

:end1
del %root%\temp.bat
del %root%\temp.txt
set i=
set j=
set filenum=
set dirnum=
set root=
set rootdir=
set curdir=
set curfile=
That's not a correct translation. Let's do it properly:

The following is a file traversal program, originally from the DOS version of NetEase Guangzhou Station.
http://fe2.gz.163.com/cgi/readsrh?b=DOS&t=21718&i=21882&al=5&n=0&l=40&back=2&st=1&kw=willsort

The original text uses two external programs, VARSET and LMOD, which may be downloaded from this station or the new DOS era.

@echo off
rem ///////////////////Search all *.txt files in all directories///////////////////

rem Find *.txt in the current directory (root directory)
for %%a in (*.txt) do type %%a

rem The following is to find all *.txt in all subdirectories of the current directory (root directory)

set i=1
set j=1
set filenum=0
set dirnum=0

varset root=FULL of . >temp.bat
call temp.bat

varset rootdir=string(3) %root% >temp.bat
call temp.bat

dir /ad /b /s >temp.txt

varset dirnum=lines temp.txt >temp.bat
call temp.bat

:loop1
type %root%\temp.txt | %root%\LMOD /L%i% set curdir= >%root%\temp.bat
call %root%\temp.bat

varset curdir=string(3) %curdir% >%root%\temp.bat
call %root%\temp.bat

cd %curdir%
echo %curdir%
set j=1
:loop2
%root%\varset filenum=files *.txt >%root%\temp.bat
call %root%\temp.bat
if %filenum%==0 goto end2

dir *.txt /b | %root%\LMOD /L%j% set curfile= >%root%\temp.bat
call %root%\temp.bat

type %curfile%

if %j%==%filenum% goto end2

%root%\varset j=%j%+1 >%root%\temp.bat
call %root%\temp.bat
goto loop2
:end2
cd %rootdir%

if %i%==%dirnum% goto end1

%root%\varset i=%i%+1 >%root%\temp.bat
call %root%\temp.bat
goto loop1

:end1
del %root%\temp.bat
del %root%\temp.txt
set i=
set j=
set filenum=
set dirnum=
set root=
set rootdir=
set curdir=
set curfile=
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 12 Posted 2004-01-12 00:00 ·  中国 山东 烟台 联通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Here is the translation:

The following is a program that receives keyboard input strings. The original text comes from the teaching room of this site.
http://model.chinajewelry.net/dos/dosbbs/dispbbs.asp?boardID=12&replyID=34149&ID=5283&skin=1

The key technique in this article lies in the skillful combination of FC and DEBUG. The usage of %TEMP%.\filename.ext is also very skillful. The usage of %%? is also novel.

---------------------------------------

:: 获取用户输入 - 包含错误检查
@echo off
echo e102'set %%1='> %temp%.\t1.dat
for %%? in (w q) do echo %%?>> %temp%.\t1.dat
:input
echo.
echo 输入内容:
FC con nul /lb1 /n |FIND "1:" > %temp%.\t2.bat
:: 错误检查开始
FIND "|" %temp%.\t2.bat > nul
if not errorlevel=1 goto error
FIND "=" %temp%.\t2.bat > nul
if not errorlevel=1 goto error
FIND " nul
if not errorlevel=1 goto error
FIND ">" %temp%.\t2.bat > nul
if not errorlevel=1 goto error
:: 错误检查结束
DEBUG %temp%.\t2.bat nul
call %temp%.\t2.bat 字符串
for %%? in (t1.dat t2.bat) do del %temp%.\%%?
echo 字符串=%字符串%
goto eof
:error
echo.
echo @PROMPT Invalid input. Invalid characters: $Q $L $G $B$_> %temp%.\t2.bat
%comspec% /c %temp%.\t2.bat |FIND ":"
goto input
:eof
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 13 Posted 2004-01-13 00:00 ·  中国 浙江 杭州 电信
银牌会员
★★
三生缘里笑红尘
Credits 1,063
Posts 292
Joined 2003-03-09 00:00
23-year member
UID 1073
Gender Male
Status Offline
Floor 14 Posted 2004-01-13 00:00 ·  中国 浙江 杭州 电信
银牌会员
★★
三生缘里笑红尘
Credits 1,063
Posts 292
Joined 2003-03-09 00:00
23-year member
UID 1073
Gender Male
Status Offline
Brother willsort, please take a look at my post
http://model.chinajewelry.net/dos/dosbbs/dispbbs.asp?boardID=9&ID=8920

Floor 15 Posted 2004-01-14 00:00 ·  中国 广东 深圳 鹏博士宽带
初级用户
Credits 197
Posts 21
Joined 2004-01-09 00:00
22-year member
UID 15212
Gender Male
Status Offline
These are all very classic batch processing programs, which are very worthy for beginners to learn, refer to and experience. If you don't want the post to be filled with water, then please ask the moderator to put it at the top! Don't let the post sink.
Forum Jump: