How can I show the progress of a long running operation in windows batch (cmd) file in percentage? Can you share some example code?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Here is how...
Note: This code is a slightly modified version of this answer.
@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