执行:
C:>TEST5 A
屏幕上就出现是否将A:盘格式化的内容。
注意:为了防止参数为空的情况,一般会将字符串用双引号(或者其它符号,注意不能使用保留符号)括起来。
如:if [%1]==[A] 或者 if %1*==A*
5、GOTO
建立TEST6.BAT,文件内容如下:
@ECHO OFF
IF EXIST C:AUTOEXEC.BAT GOTO _COPY
GOTO _DONE
:_COPY
COPY C:AUTOEXEC.BAT D:
:_DONE
注意:
(1) 标号前是ASCII字符的冒号":",冒号与标号之间不能有空格。
(2) 标号的命名规则与文件名的命名规则相同。
(3) DOS支持最长八位字符的标号,当无法区别两个标号时,将跳转至最近的一个标号。
6、FOR
建立C:TEST7.BAT,文件内容如下:
@ECHO OFF
FOR %%C IN (*.BAT *.TXT *.SYS) DO TYPE %%C
运行:
C:>TEST7
执行以后,屏幕上会将C:盘根目录下所有以BAT、TXT、SYS为扩展名的文件内容显示出来(不包括隐藏文件)。
win2000命令行方式批处理BAT文件技巧
文章结构
1. 所有内置命令的帮助信息
2. 环境变量的概念
3. 内置的特殊符号(实际使用中间注意避开)
4. 简单批处理文件概念
5. 附件1 tmp.txt
6. 附件2 sample.bat
###########################
1. 所有内置命令的帮助信息
###########################
ver
cmd /?
set /?
rem /?
if /?
echo /?
goto /?
for /?
shift /?
call /?
其他需要的常用命令
type /?
find /?
findstr /?
copy /?
下面将所有上面的帮助输出到一个文件
echo ver >tmp.txt
ver >>tmp.txt
echo cmd /? >>tmp.txt
cmd /? >>tmp.txt
echo rem /? >>tmp.txt
rem /? >>tmp.txt
echo if /? >>tmp.txt
if /? >>tmp.txt
echo goto /? >>tmp.txt
goto /? >>tmp.txt
echo for /? >>tmp.txt
for /? >>tmp.txt
echo shift /? >>tmp.txt
shift /? >>tmp.txt
echo call /? >>tmp.txt
call /? >>tmp.txt
echo type /? >>tmp.txt
type /? >>tmp.txt
echo find /? >>tmp.txt
find /? >>tmp.txt
echo findstr /? >>tmp.txt
findstr /? >>tmp.txt
echo copy /? >>tmp.txt
copy /? >>tmp.txt
type tmp.txt
#############################
2. 环境变量的概念
#############################
C:Program Files>set
ALLUSERSPROFILE=C:Documents and SettingsAll Users









