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-20 16:38
中国DOS联盟论坛 » DOS学习入门 & 精彩文章 (教学室) » Collection of DOS Command Tips View 5,697 Replies 23
Original Poster Posted 2002-12-31 00:00 ·  中国 浙江 宁波 电信
初级用户
Credits 169
Posts 15
Joined 2002-12-29 00:00
23-year member
UID 635
Gender Male
Status Offline
Batch processing has many techniques and can accomplish many things that can't be done well in Windows.
@echo off //Cancel the display of command operation on the screen
echo. |date| find "Current" //Only display the date
echo. |time| find "Current" //Only display the time
:: //Equivalent to rem
call //Call another batch file
del %0 //Self - delete
if "%1" == "string" goto //For example, if "%1" == "/p" goto p
if "%1" == "string" command //if "%1" == "/p" dir /w/p c:
if exist file command //Run the command if the file exists
copy /b //Merge files
fdisk /mbr //Uninstall the master boot record. If the master boot record is overwritten by LILO, it can be used to clear it
prompt $p$g //Restore the prompt
echo Free and Open > new DOS.txt //Write Free and Open into new DOS.txt
echo Happy New year >> new DOS.txt //Continue to write Happy New year into new DOS.txt
lh //Load the device into the upper memory. For example, lh smartdrv /x
mode 80 Restore the default display settings
mode mono Activate the monochrome display
mode con:cols=40-80 lines=25-50 //40-80;25-50 are parameters
Keyboard control
mode con:rate=32 delay=1 //Agile
mode con:rate=20 delay=4 //Accurate
mode con:rate=20 delay=2 //Default
Print control
mode com1:9600,8,N,1 //Fast
mode lpt1=com1
mode com1:2400,8,N,1 //Slow
mode lpt1=com1
echo Hello > prn //Test printing
Install CD - ROM
Add in config.sys
devicehigh=boot\CD-ROM.sys /d MSCD001
Add in autoexec.bat
path boot
mscdex /d MSCD001 /m 12
//CD-ROM.sys can be replaced by universal CD - ROM IDE.sys
//Menu display, selection
echo 1.
echo 2.
echo 3.
...
echo 9.
choice /c:123456789 /n Please choose:
if errorlevel 9 goto 9
if errorlevel 8 goto 8
if errorlevel 7 goto 7
if errorlevel 6 goto 6
if errorlevel 5 goto 5
if errorlevel 4 goto 4
if errorlevel 3 goto 3
if errorlevel 2 goto 2
if errotlevel 1 goto 1

A simple example
@echo off
if "%1" == "/all" goto all
If exist c:\1.txt goto 1
echo The file 1.txt is not found
goto end
:1
echo The file 1.txt exists, press any key to read...
pause > nul
type 1.txt | more
goto end
:all
dir /s/w/p 1.txt
:: Display all 1.txt in the sub - directories of the C drive
:end
Floor 2 Posted 2002-12-31 00:00 ·  中国 北京 263网络通信股份有限公司
银牌会员
★★★
nre
Credits 1,210
Posts 361
Joined 2002-12-28 00:00
23-year member
UID 629
Gender Male
Status Offline
Not bad~ But I hope to classify them again, because this way is not convenient for searching and learning.
Ask a question: How to use DEL %0?
Correct some improper places above.
FDISK/MBR does not delete the MBR (Master Boot Record), but overwrites the current MBR content with the default master boot record.
copy /b alone cannot achieve merging. /B specifies merging in binary mode, and /A is for ASIIC files.
copy file1 + file2 +... fileN target file
choice, mode, more are all external commands. When compiling BAT, if these commands are used, it is necessary to consider whether the file exists.

Teamwork !
Floor 3 Posted 2003-01-01 00:00 ·  中国 浙江 宁波 电信
初级用户
Credits 169
Posts 15
Joined 2002-12-29 00:00
23-year member
UID 635
Gender Male
Status Offline
Thanks to NRE for pointing out the inappropriate parts. Add "del %0" at the end of the batch file, and it will self-delete after completion. Most of the above commands can be directly inserted and used in the batch file. It's just that only a part of the skills and less commonly used command parameters are listed, and there are many more to be listed after I sort them out. Of course, if anyone has questions in this regard, I will be happy to answer for you.
Floor 4 Posted 2003-01-01 00:00 ·  中国 北京 263网络通信股份有限公司
银牌会员
★★★
nre
Credits 1,210
Posts 361
Joined 2002-12-28 00:00
23-year member
UID 629
Gender Male
Status Offline
This is the first time I've seen this usage of DEL. Classic~
I tried it, and %0 stores the file name of the called file, excluding the extension. So you need to add the extension. del %0.bat to achieve automatic deletion. But when doing this, after running, there will be a prompt of BATCH FILE MISSING.

Teamwork !
Floor 5 Posted 2003-01-01 00:00 ·  中国 山东 滨州 联通
高级用户
★★
Credits 948
Posts 271
Joined 2002-12-13 00:00
23-year member
UID 502
Gender Male
From sd
Status Offline
How is the virtual disk created after booting with the built-in startup disk of Win98?
Floor 6 Posted 2003-01-06 00:00 ·  中国 广东 茂名 电信
初级用户
Credits 123
Posts 6
Joined 2003-01-06 00:00
23-year member
UID 691
Gender Male
Status Offline
What is the function of DEL %0 self-deletion????
Floor 7 Posted 2003-01-06 00:00 ·  中国 广东 茂名 电信
初级用户
Credits 123
Posts 6
Joined 2003-01-06 00:00
23-year member
UID 691
Gender Male
Status Offline
According to your writing, in DOS, do you need to install UCDOS?
Floor 8 Posted 2003-01-06 00:00 ·  中国 广东 茂名 电信
初级用户
Credits 123
Posts 6
Joined 2003-01-06 00:00
23-year member
UID 691
Gender Male
Status Offline
Who can teach me under DOS, I only know how to use FDISK CD DIR DEL SCANDISK MD RD and other commands. Is there any other ones for DOS masters??? Please give more more more guidance!
Floor 9 Posted 2003-01-06 00:00 ·  中国 广东 佛山 禅城区 电信
元老会员
★★★★
Credits 5,170
Posts 1,637
Joined 2002-10-16 00:00
23-year member
UID 8
Gender Male
From 广东佛山
Status Offline
There are still many.
diskcopy
msav
xcopy
smartdrv
help
deltree
format
sys
...
我的网志
http://hzmys.blog.163.com/
我的网盘
firststep.qjwm.com
fsmys.ys168.com
ssmys.ys168.com
www.brsbox.com/fsmys
www.brsbox.com/ssmys
www.brsbox.com/ccdos
Floor 10 Posted 2003-01-06 00:00 ·  美国 肯塔基州 费耶特县 列克星敦 Charter_Communications
系统支持
★★★★★★
“新DOS时代”站长
Credits 27,736
Posts 10,521
Joined 2002-10-09 12:00
23-year member
UID 9
Status Offline
The command DEL %0 is quite problematic because the %0 parameter actually returns the command line used to execute this batch file. For example, when I want to execute the ABC.BAT batch file, I can enter ABC or ABC.BAT on the command line to execute it. In this way, the value of %0 may be completely different, that is, its value may be "ABC" or "ABC.BAT", etc. And if it is the former, DEL %0, that is, DEL ABC, is impossible to delete the ABC.BAT itself.
Wengier - 新DOS时代

欢迎大家来到我的“新DOS时代”网站,里面有各类DOS软件和资料,地址:
http://wendos.mycool.net/

E-Mail & MSN: wengierwu AT hotmail.com (最近比较忙,有事请联系DOSroot和雨露,谢谢!)

Floor 11 Posted 2006-09-29 06:17 ·  中国 北京 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
Then execute two lines:

DEL %0
DEL %0.BAT

Write both, there will always be one that can delete itself normally~:)
Floor 12 Posted 2006-09-29 07:27 ·  中国 四川 成都 教育网
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 13 Posted 2006-09-29 07:47 ·  中国 北京 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline

C:\TEMP\t 1 2 3>type demo.bat

echo.
echo %0
echo %~f0
pause
del %~f0
C:\TEMP\t 1 2 3>


System prompt:

C:\TEMP\t 1 2 3>demo.bat

C:\TEMP\t 1 2 3>echo.


C:\TEMP\t 1 2 3>echo demo.bat
demo.bat

C:\TEMP\t 1 2 3>echo C:\TEMP\t 1 2 3\demo.bat
C:\TEMP\t 1 2 3\demo.bat

C:\TEMP\t 1 2 3>pause
Press any key to continue . . .

C:\TEMP\t 1 2 3>del C:\TEMP\t 1 2 3\demo.bat
The system cannot find the file specified.

C:\TEMP\t 1 2 3>


Original note: When deleting a directory name with spaces, there were no quotes in the DEL command :)


C:\TEMP\t 1 2 3>type demo.bat
del "%~f0"


Execution:

C:\TEMP\t 1 2 3>demo.bat

C:\TEMP\t 1 2 3>del "C:\TEMP\t 1 2 3\demo.bat"


It was deleted~ :)

Thanks to electronixtar for the wonderful %~f0 code, I learned a lot more~ :)
Later, the comment for for /? : %~fI - Expand %I to a fully qualified pathname

This %~f0 is really wonderful~ :)
Floor 14 Posted 2006-09-30 03:52 ·  中国 广东 东莞 电信
中级用户
★★
Credits 282
Posts 130
Joined 2006-09-20 22:25
19-year member
UID 63201
From 广东
Status Offline
Learning
Floor 15 Posted 2006-10-23 23:24 ·  中国 湖北 孝感 安陆市 电信
新手上路
Credits 18
Posts 6
Joined 2006-10-21 02:59
19-year member
UID 67413
Status Offline
Bookmarked
Forum Jump: