@ECHO off WHERE mycommand 2>NUL IF%ERRORLEVEL%NEQ0 ( ECHO mycommand wasn't found ) ELSE ( ECHO mycommand found ) PAUSE
判斷檔案是否存在
檢查7z.exe是否存在
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
@ECHO off SET filepath=%ProgramFiles%\7-Zip\ SET filename=7z.exe
cd%filepath% IFEXIST%filename% ( ECHO%filename% found ECHO%CD% ) ELSE ( ECHO%filename% wasn't found )
:: BAT File所在位置 %~dp0 cd %~dp0 ECHO%CD% PAUSE
日期與時間變數
1 2 3 4 5 6 7 8 9 10 11 12 13
::民國年 set /a year=%date:~,4%-1911 ::西元年 set year=%date:~,4% ::月 set month=%date:~5,2% ::日 set day=%date:~8,2% ::今天日期 set Today=%year%%month%%day% ::時間 set NowTimeTmp=%time::=% set NowTime=%NowTimeTmp:~0,6%