當然不是的 因為 > 被用來當作寫檔的功能,正確的指令 倒是不知道
如: DIR/W >C:\AA.LOG
依參考下面文章 來源:http://www.computerhope.com/if.htm
The below example would work if you want it all on one line:
IF EXIST filename. (del filename.) ELSE echo filename. missing
If Command Extensions are enabled IF changes as follows:
IF [/I] string1 compare-op string2 command
IF CMDEXTVERSION number command
IF DEFINED variable command
where compare-op may be one of:
EQU - equal
NEQ - not equal
LSS - less than
LEQ - less than or equal
GTR - greater than
GEQ - greater than or equal
例1:ERRORLEVEL NUMBER比較
IF %ERRORLEVEL% LEQ 1 goto okay
例2:數字比較
@For /f "tokens=1-3 delims=/ " %%a in ('date /t') do (set sysdate=%%a-%%b-%%c)
if %sysdate% LSS 2008-10-06 goto exit
例3:字串比較
注意!! 寫慣java delphi等程式的人,習慣把字串前後包雙引號
但測試後發現,要就兩邊都要包雙引號,一邊有包一邊
沒包,或是變數值由其他功能得出,是會讓你產生bug
的….要小心.
如下例,set str1=ABC,ABC沒包雙引號,但if那行
EUQ ABC若改寫成
EQU "ABC",還是run出結果會是Both is different..。
@echo off
set str1=ABC
IF %str1% EQU ABC (
echo Both is same..
) else (
echo Both is different..
)
留言列表