如何以百分比显示Windows批处理(cmd)文件中长时间运行的操作的进度?你能分享一些示例代码吗?
答案 0 :(得分:0)
以下是......
注意:此代码是this答案的略微修改版本。
@echo off
for /f %%a in ('copy /Z "%~dpf0" nul') do set "CR=%%a"
FOR /L %%n in (1,1,10) DO (
call :show_progress %%n 10
ping localhost -n 2 > nul
)
echo Done!
exit /b
:show_progress
setlocal EnableDelayedExpansion
set current_step=%1
set total_steps=%2
set /a "progress=(current_step * 100) / total_steps"
set /p ".=Progress: !progress!%%!CR!" <nul
if !progress! equ 100 echo.
exit /b
答案 1 :(得分:0)
一个例子是扫描一个大文件/数据库,显示进度而不是闪烁的光标,好久了!
set c=<no. of lines in file>
for /l %i in (1,1,%c%) do cls & set /p="Scanning for target ... "<nul & (set /a per=%i00/%c% >nul & echo !per!%)& ping 127.0.0.1 -n 2 > nul & REM when target found, send agents to greet
echo Complete.
括号 ()
中的代码表示进度百分比。
在 Win 10 CmD 中测试>