方法一:ping
缺點:時間精度爲1秒,不夠精確
方法二:vbs start /wait
缺點:生成臨時文件
優勢:時間精度爲0.001秒,精度高
@echo off
echo wscript.sleep 5000 > sleep.vbs
start /wait sleep.vbs
start gdh.txt
del /f /s /q sleep.vbs
方法三:vbs cscript
@echo off
echo wscript.sleep 5000 > sleep.vbs
@cscript sleep.vbs > nul
start gdh.txt
del /f /s /q sleep.vbs
方法四:choice
優勢:時間精確,CPU佔用低,是最佳選擇
@echo off
choice /t 5 /d y /n > nul
start gdh.txt
方法五:for+set+if,時間精度爲0.01秒
缺點:CPU佔用高,語句過長,不經常使用
@echo off
setlocal enableextensions
echo %time%
call :ProcDelay 500
echo %time%
start gdh.txt
:ProcDelay delayMSec_
setlocal enableextensions
for /f "tokens=1-4 delims=:. " %%h in ("%time%") do set start_=%%h%%i%%j%%k
:_procwaitloop
for /f "tokens=1-4 delims=:. " %%h in ("%time%") do set now_=%%h%%i%%j%%k
set /a diff_=%now_%-%start_%
if %diff_% LSS %1 goto _procwaitloop
endlocal & goto :EOF
我使用的是這個批處理,惟一很差就是有窗口
@echo off
:: 模擬進度,有剩餘時間、已完成進度、進度條的顯示
:: code by
color 1f
title.
mode con lines=10
rem 進度條 ▉▉▉▉▉
set work=0
set n=0
set mo=0
set number=0
rem all是總數
set all=10
set time=%all%
:show
:check
if %number% GTR %mo% set num=%num%▉&set /a mo=%mo%+1&goto check
:2
cls
echo 進度: %n% / %all% ★程序正在啓動請稍等★ 剩餘時間:%time%秒
echo.
echo.
echo 完成 %work% %%%
echo.
if not "%num%"=="" echo %num%
if not "%num%"=="" echo %num%
if %work%==100 goto end
ping 127.1 -n 2 >nul
set /a n=%n%+1
set /a time=%all%-%n%
set /a work=(%n%)*100/(%all%)
set /a number=%work%/3
set /a number=%number%+1
goto show
endlocal
:end
@echo off
start C:\Progra~1\tools\xsdy\1.exe
exit