2013-06-21 75 views
0

這裏是我的代碼,(我試圖做一個進度條,但失敗了)。批量變量字符串操作不起作用

@echo off & setlocal enabledelayedexpansion 
set bar=********** 
set cnt=0 
:LOOP 
cls 
set /A cnt+=1 
echo.Progress:!bar:~0,%cnt%! 
ping -n 1 www.google.com > nul 2>&1 
if "%cnt%" NEQ 10 goto :LOOP 
echo.finished. 
pause > nul 
exit /b 

我得到這個作爲輸出: 吧:〜0,1 吧:〜0.2 吧:〜0,3 等。等等。 我想讓它去的,如:*, **, ***基本上每秒鐘增加1個星號。

回答

1

試試這個:

@echo off & setlocal enabledelayedexpansion 
set "bar=**********" 
set /a cnt=0 
:LOOP 
cls 
set /A cnt+=1 
SET "progressbar=!bar:~0,%cnt%!" 
ECHO(Progress:%progressbar% 
ping -n 1 www.google.com > nul 2>&1 
if %cnt% NEQ 10 goto :LOOP 
ECHO(finished. 

REM example without CLS 
<NUL set/p "=Progress:" 
:LOOPING 
<NUL set/p"=*" 
ping -n 1 www.google.com > nul 2>&1 
SET /a count+=1 
if %count% NEQ 10 goto :LOOPING 
ECHO(&ECHO(finished.