windows batch

批次檔中迴圈的錯誤偵測及跳出

1
2
3
4
5
setlocal enabledelayedexpansion
for %%f in (C:\Windows\*) do (
runsomeapplication.exe /with "parameters"
if !errorlevel! neq 0 exit /b !errorlevel!
)

改檔名串接日期時間格式

1
2
3
4
5
6
7
echo %date%
echo %date:~0,4%%date:~5,2%%date:~8,2%
echo %time%
echo %time:~0,5%
echo %time:~0,2%%time:~2,2%
echo %time:~0,2%%time:~3,2%
ren snapshot.csv snapshot.%date:~0,4%%date:~5,2%%date:~8,2%.csv