- ©«¤l
- 83
- ¥DÃD
- 73
- ºëµØ
- 0
- ¿n¤À
- 164
- ÂI¦W
- 0
- §@·~¨t²Î
- xp
- ³nÅ骩¥»
- Office 2003
- ¾\ŪÅv
- 20
- ©Ê§O
- ¨k
- µù¥U®É¶¡
- 2013-8-12
- ³Ì«áµn¿ý
- 2015-12-13
|
[¤À¨É] BAT§å¦¸«ü¥O¡G IF ªº¥\¯à¤¶²Ð
BAT§å¦¸«ü¥O¡G IF ªº¥\¯à¤¶²Ð
IF ¡G¦b§å¦¸Àɤ¤°õ¦æ±ø¥ó³B²z¡C
«ü¥O¸Ô¸Ñ¡G
IF [NOT] ERRORLEVEL number command
IF [NOT] string1==string2 command
IF [NOT] EXIST filename command
NOT ªí¥Ü Windows XP À³¸Ó¥u¦³¦b±ø¥ó¬°°°®É
¤~°õ¦æ©R¥O¡C
ERRORLEVEL number ·í¤W¤@Ó°õ¦æªºµ{¦¡¶Ç¦^ªºµ²§ô½X¤j©ó©Î
µ¥©ó«ü©w¼Æ¦r®É¡A«h±ø¥ó¬°¯u¡C
string1==string2 ·í«ü©wªº¤å¦r¦r¦ê¬Û²Å¦X®É¡A«h±ø¥ó
¬°¯u¡C
EXIST filename ¦pªG«ü©wªºÀɦW¦s¦b®É¡A«h±ø¥ó
¬°¯u¡C
command «ü©w·í±ø¥ó¬°¯u®É©Òn°õ¦æªº©R¥O¡C
©R¥O¤§«á¥i¥H±µµÛ ELSE ©R¥O¡C·í«ü©w±ø¥ó¬°
°°®É¡Aºò±µ¦b ELSE ©R¥O¤§«áªº©R¥O
±N·|³Q°õ¦æ¡C
ELSE ¤l¥y¥²¶·¥X²{¦b IF ¤§«áªº¦P¤@¦æ¡C
¨Ò¦p:
IF EXIST filename. (
del filename.
) ELSE (
echo filename. missing.
)
¥H¤U©R¥OµLªk§@¥Î¡A¦]¬° del ©R¥O¥²¶·¥H´«¦æ¦r¤¸¨Óµ²§À:
IF EXIST filename. del filename. ELSE echo filename. missing
¤U±©R¥O¤]µLªk§@¥Î¡A¦]¬° ELSE ©R¥O¥²¶·¦b»P IF ©R¥O¦P¤@¦æªºµ²§À:
IF EXIST filename. del filename.
ELSE echo filename. missing
¤U±©R¥O¥u¦³¦b¼g¦¨¤@¦æ®É¤~¯à§@¥Î:
IF EXIST filename. (del filename.) ELSE echo filename. missing
¦pªG±z±Ò¥ÎÂX¥R©R¥O¡AIF ªºÅܧó¦p¤U:
IF [/I] string1 compare-op string2 ©R¥O
IF CMDEXTVERSION ¼Æ¦r©R¥O
IF DEFINED ÅܼƩR¥O
compare-op ¥i¥H¬O:
EQU - µ¥©ó
NEQ - ¤£µ¥©ó
LSS - ¤p©ó
LEQ - ¤p©ó©Îµ¥©ó
GTR - ¤j©ó
GEQ - ¤j©ó©Îµ¥©ó
¦Ó¦pªG«ü©w /I °Ñ¼Æ¡A«h°õ¦æ°Ï¤À¤j¤p¼gªº¦r¦ê¤ñ¹ï¡C
¦¹ /I °Ñ¼Æ¤]¥i¨Ï¥Îstring1==string2 ®æ¦¡©ó IF ©R¥O¡C
³o¨Ç¤ñ¹ï¬O³q¥Îªº¡A¦]¬°¦b¤ñ¹ï¤¤¡A¦pªG string1 ¤Î string2 ¨âªÌ¬Ò¥Ñ¤Q¶i¦ì¼Æ¦r©Òºc¦¨¡A«h¦r¦ê±N·|Âà´«¬°¼Æ¦r¡A¨Ã°õ¦æ¼Æ¦rªº¤ñ¹ï¡C
CMDEXTVERSION ±ø¥ó¦¡ªº¹B§@©M ERRORLEVEL ¤@¼Ë¡A°£«D¥¦©M»PÂX¥R©R¥O¬ÛÃöªº¤º³¡ª©¥»½s¸¹§@¤ñ¹ï¡C
²Ä¤@Óª©¥»¬° 1¡CYÂX¥R©R¥O¤j´T«×¦a¼W±j®É´N¦A¥[ 1¡C
·íÂX¥R©R¥O°±¥Î®É¡ACMDEXTVERSION ±ø¥ó¦¡¥Ã»·¤£¬°¯u¡C
DEFINED ±ø¥ó¦¡ªº¹B§@©M EXISTS ¤@¼Ë¡A°£«D¥¦±a¦³Àô¹ÒÅܼƦWºÙ¡A¦pªGÀô¹ÒÅܼƤw©w¸q«h¶Ç¦^ true È¡C
%ERRORLEVEL% ±NÂX¥R¨ì¥Nªí¥Ø«e ERRORLEVEL Åܼƪº¤@Ó¦r¦ê¡A«e´£¬O¤w¸g¨S¦³¦W¬° ERRORLEVEL ªºÀô¹ÒÅܼơA¦b³oÓ±¡ªp¤U¡A±z·|±o¨ì¥¦ªºÈ¡C
¨Ï¥Î¦¹È©M¤W±ªº¼Æ¦r¤ñ¹ï¹Bºâ¤¸¡A±z¥i¥H§@¤U¦Cªº¿ï¾Ü:
goto answer %ERRORLEVEL%
:answer0
´£¥Ü±zÁä¤J Y ¥[¥H½T©w
:answer1
´£¥Ü±zÁä¤JN ¥[¥H§_©w
±z¤]¥i¨Ï¥Î¤W±ªº¼Æ¦r¤ñ¹ï:
IF %ERRORLEVEL% LEQ 1 goto okay
%CMDCMDLINE% ±NÂX¥R¨ì¤ñ CMD.EXE ªº¥ô¦ó³B²zµ{§Ç§ó¦¶Çµ¹ CMD.EXE ªºì©l©R¥O¦C¡A«e´£¬O¤w¸g¨S¦³¦W¬° CMDCMDLINE ªºÀô¹ÒÅܼơA¦b³oÓ±¡§Î¤U¡A±z·|±o¨ì¥¦ªºÈ¡C
%CMDEXTVERSION% ±NÂX¥R¦¨¤@Óªí¥Ü¥Ø«e CMDEXTVERSION Ȫº¦r¦ê¡Aªí¥Ü¨S¦³¦W¬° CMDEXTVERSION ªºÀô¹ÒÅܼơC
³oºØ±¡ªp¤U±z±N·|±o¨ì¥¦ªºÈ¡C |
|