如何将进度条添加到批处理文件?

How to add a progress bar to batch file?

我已经搜索过了,但还没有真正找到我要找的东西,我只想要一个简单的进度条,在批处理文件下载这些 lua 文件时显示完成百分比。

    @echo off
REM The title of the CMD window
title Bot of legends LibUpdater v1.3 by Herkules101 (Updated by Bing)
REM the color of the text
color e
echo LibUpdater : The automatic library updater
echo.
echo This tool will automatically download and install BoL libraries with ease.
echo ______________________________________________________________________________
echo.
echo -- Libraries available for installation --
echo.
REM The current libraries the program will download
echo [AllClass.lua]              [AoE_SkillShot_Position.lua]
echo [AQLib.lua]                 [BestCollision.lua]
echo [ChampionLib.lua]           [Collision.lua]
echo [ComboClass.lua]            [ComboLib.lua]
echo [CustomPermaShow.lua]       [DataManager.lua]
echo [DRAW_POS_MANAGER.lua]      [DrawDamageLib.lua]
echo [Edited_AllClass.lua]       [ezCollision.lua]
echo [ezLibrary.lua]             [FastCollision.lua]
echo [FTER_SOW.lua]              [iLibraryENC.lua]
echo [ImBeastyLib.lua]           [imLib.lua]
echo [iSAC.lua]                  [ITEM_MANAGER.lua]
echo [ItemRecipes.lua]           [LEVEL.lua]
echo [LineSkillShotPosition.lua] [MapPosition.lua]
echo [PPrediction.lua]           [Prodiction.lua]
echo [SALib.lua]                 [Selector.lua]
echo [ShadowVayneLib.lua]        [SourceLib.lua]
echo [SOW.lua]                   [spellDmg.lua]
echo [spellList.lua]             [SxOrbWalk.lua]
echo [VPrediction.lua]           [YooLib.lua]
echo [Yolib.lua]

echo.
echo.
pause
cls
:install
REM Ask user whether they would like to Download libraries Y = goto download N = goto exit
Set /P _install= Download/update the current libraries available? (Y/N) :
If /I "%_install%"=="Y" goto download
If /I "%_install%"=="N" goto exit
) Else (
REM If the user doesn't enter Y or N (Case insensitive) this message will be displayed and the user asked to answer again.
echo Invalid argument - this program is case insensitive.
ping 123.45.67.89 -n 1 -w 1800 > nul
cls
goto install

:exit
REM Exit the program
cls
echo Exiting . . .
ping 123.45.67.89 -n 1 -w 2000 > nul
exit

:download
REM Start the download process
cls
cd Tools
REM Make temporary directory to store libraries in
mkdir temp
copy wget.exe temp
cls
echo Downloading and installing libraries . . . please stand by
cd temp
REM GitHub/BitBucket URL's // Will always download the latest version that the developer uploads.
wget --no-check-certificate -q https://raw.githubusercontent.com/SurfaceS/BoL_Studio/master/Scripts/Common/AllClass.lua
wget --no-check-certificate -q https://raw.githubusercontent.com/Dienofail/BoL/master/common/AoESkillShotPosition.lua
ren "AoESkillShotPosition.lua" "AoE_SkillShot_Position.lua"
wget --no-check-certificate -q https://raw.githubusercontent.com/bolqqq/BoLScripts/master/common/AQLib.lua
wget --no-check-certificate -q https://raw.githubusercontent.com/Dienofail/BoL/master/common/BestCollision.lua
wget --no-check-certificate -q https://raw.githubusercontent.com/wquantum1/BoL/master/ChampionLib.lua
wget --no-check-certificate -q https://bitbucket.org/Klokje/public-klokjes-bol-scripts/raw/b891699e739f77f77fd428e74dec00b2a692fdef/Common/Collision.lua
wget --no-check-certificate -q https://raw.githubusercontent.com/SurfaceS/BoL_Studio/master/Scripts/Common/ComboClass.lua
wget --no-check-certificate -q https://raw.githubusercontent.com/LlamaBoL/BoL/master/Common/comboLib.lua
wget --no-check-certificate -q https://raw.githubusercontent.com/Superx321/BoL/master/common/CustomPermaShow.lua
wget --no-check-certificate -q https://raw.githubusercontent.com/BoL-Apple/BoL/master/Common/DataManager.lua
wget --no-check-certificate -q https://raw.githubusercontent.com/fter44/ilikeman/master/common/DRAW_POS_MANAGER.lua
wget --no-check-certificate -q https://raw.githubusercontent.com/fter44/ilikeman/master/common/Edited_AllClass.lua 
wget --no-check-certificate -q https://raw.githubusercontent.com/soulcaliber/BoL/master/Common/ezCollision.lua
wget --no-check-certificate -q https://raw.githubusercontent.com/soulcaliber/BoL/master/Common/ezLibrary.lua
wget --no-check-certificate -q https://bitbucket.org/boboben1/bol-scripts/raw/7dae5a6294b9db14b5430b72d9b5c2c6eb8758a1/Misc/FastCollision.lua
wget --no-check-certificate -q https://raw.githubusercontent.com/fter44/ilikeman/master/common/FTER_SOW.lua
wget --no-check-certificate -q http://iuser99.com/libraries/iLibraryENC.lua
wget --no-check-certificate -q http://scripts.imbeasty.com/ImBeastyLib.lua
wget --no-check-certificate -q https://bitbucket.org/Klokje/public-klokjes-bol-scripts/raw/master/Common/ImLib.lua
wget --no-check-certificate -q https://raw.githubusercontent.com/BoL-Apple/BoL/master/Common/iSAC.lua
wget --no-check-certificate -q https://raw.githubusercontent.com/fter44/ilikeman/master/common/ITEM_MANAGER.lua
wget --no-check-certificate -q https://raw.githubusercontent.com/fter44/ilikeman/master/common/LEVEL.lua
wget --no-check-certificate -q https://raw.githubusercontent.com/Dienofail/BoL/master/common/LineSkillShotPosition.lua
wget --no-check-certificate -q https://raw.githubusercontent.com/c3iL/BoL-1/master/MapPosition.lua
wget --no-check-certificate -q https://raw.githubusercontent.com/Dienofail/BoL/master/common/PPrediction.lua
wget --no-check-certificate -q https://bitbucket.org/Klokje/public-klokjes-bol-scripts/raw/master/Test/Prodiction/Prodiction.lua
wget --no-check-certificate -q https://raw.githubusercontent.com/UglyOldGuy/NintendoBoL/master/BH%20Bundle/Common/SALib.lua
wget --no-check-certificate -q http://iuser99.com/scripts/Selector.lua
wget --no-check-certificate -q https://raw.githubusercontent.com/Superx321/BoL/master/common/ShadowVayneLib.lua
wget --no-check-certificate -q https://raw.githubusercontent.com/gbilbao/Bilbao/master/BoL1/Common/SourceLib.lua
wget --no-check-certificate -q https://raw.githubusercontent.com/gbilbao/Bilbao/master/BoL1/Common/SOW.lua
wget --no-check-certificate -q https://raw.githubusercontent.com/SurfaceS/BoL_Studio/master/Scripts/Common/spellList.lua
wget --no-check-certificate -q https://raw.githubusercontent.com/Superx321/BoL/master/common/SxOrbWalk.lua
wget --no-check-certificate -q https://raw.githubusercontent.com/Ralphlol/BoLGit/master/VPrediction.lua
wget --no-check-certificate -q https://raw.githubusercontent.com/Yoooooo/YoLuaProject/master/YooLib.lua
wget --no-check-certificate -q https://raw.githubusercontent.com/Yoooooo/YoLuaProjects/master/Yolib.lua
REM Pastebin Links // Will only download the pastebin links as I add them, user may not always recieve the latest version of the library untill added.
wget --no-check-certificate -q http://pastebin.com/raw.php?i=hTM4bVC6
ren "raw.php?i=hTM4bVC6" "ItemRecipes.lua"
wget --no-check-certificate -q http://pastebin.com/raw.php?i=7EDjNzuq
ren "raw.php?i=7EDjNzuq" "spellDmg.lua"
wget --no-check-certificate -q http://pastebin.com/raw.php?i=UfZ0Efax
ren "raw.php?i=UfZ0Efax" "DrawDamageLib.lua"
REM Move all of the downloaded libraries into the Scripts\Common\ folder.
xcopy "*.lua" "../../Scripts/Common" /e /y /s /i
cd..
REM Remove the temporary directory which holds the libraries.
rmdir temp /q /s
cd..
cls

REM If VPrediction.lua in Scripts\Common doesn't exist goto error
if not exist Scripts\Common\VPrediction.lua goto error
REM If VPrediction.lua exists in Scripts\Common goto success
if exist Scripts\Common\VPrediction.lua goto success

:success
REM The script successfully found VPrediction.lua leading to this message being displayed.
echo Libraries have succesfully been installed. 
echo.
echo. ~ Exiting in 5 ~
ping 123.45.67.89 -n 1 -w 5000 > nul
exit

:error
REM The script couldn't find VPrediction.lua leading to this message being displayed.
echo An error has occured during the download and installation process.
echo.
echo Please ensure that the "Tools" folder is present within your BoL installation
echo If errors persist try and disable any anti-virus that may be installed.
echo The program will now exit . . .
ping 123.45.67.89 -n 1 -w 10000 > nul

我才刚刚开始学习这些东西,所以我还是不太明白,我只是想更新我觉得有用但现在被放弃的文件,我认为有一个进度条会很好和百分比竞争状态,因为下载所有文件需要一段时间,有些人可能认为它冻结等。任何帮助将不胜感激。

针对您的情况的最简单解决方案是在您进行所有 wget 调用之前打开 echo

你可以用 @echo on

这样您就可以看到您的程序执行了多远或卡住了什么地方。

另一种选择是制作第二个批处理文件来处理 UI:

@echo off
REM The title of the CMD window
title Bot of legends LibUpdater v1.3 by Herkules101 (Updated by Bing)
REM the color of the text
color e
echo LibUpdater : The automatic library updater
echo.
echo This tool will automatically download and install BoL libraries with ease.
echo ______________________________________________________________________________
echo.
echo -- Libraries available for installation --
echo.
REM The current libraries the program will download
echo [AllClass.lua]              [AoE_SkillShot_Position.lua]
echo [AQLib.lua]                 [BestCollision.lua]
echo [ChampionLib.lua]           [Collision.lua]
echo [ComboClass.lua]            [ComboLib.lua]
echo [CustomPermaShow.lua]       [DataManager.lua]
echo [DRAW_POS_MANAGER.lua]      [DrawDamageLib.lua]
echo [Edited_AllClass.lua]       [ezCollision.lua]
echo [ezLibrary.lua]             [FastCollision.lua]
echo [FTER_SOW.lua]              [iLibraryENC.lua]
echo [ImBeastyLib.lua]           [imLib.lua]
echo [iSAC.lua]                  [ITEM_MANAGER.lua]
echo [ItemRecipes.lua]           [LEVEL.lua]
echo [LineSkillShotPosition.lua] [MapPosition.lua]
echo [PPrediction.lua]           [Prodiction.lua]
echo [SALib.lua]                 [Selector.lua]
echo [ShadowVayneLib.lua]        [SourceLib.lua]
echo [SOW.lua]                   [spellDmg.lua]
echo [spellList.lua]             [SxOrbWalk.lua]
echo [VPrediction.lua]           [YooLib.lua]
echo [Yolib.lua]

echo.
echo.
pause
cls
:install
REM Ask user whether they would like to Download libraries Y = goto download N = goto exit
Set /P _install= Download/update the current libraries available? (Y/N) :
If /I "%_install%"=="Y" goto download
If /I "%_install%"=="N" goto exit
) Else (
REM If the user doesn't enter Y or N (Case insensitive) this message will be displayed and the user asked to answer again.
echo Invalid argument - this program is case insensitive.
ping 123.45.67.89 -n 1 -w 1800 > nul
cls
goto install

:exit
REM Exit the program
cls
echo Exiting . . .
ping 123.45.67.89 -n 1 -w 2000 > nul
exit

:download
REM Start the download process
cls
cd Tools
REM Make temporary directory to store libraries in
mkdir temp
copy wget.exe temp
echo 0 >> .\temp\temp.txt
..\UI.bat  https://raw.githubusercontent.com/SurfaceS/BoL_Studio/master/Scripts/Common/AllClass.lua
..\UI.bat  https://raw.githubusercontent.com/Dienofail/BoL/master/common/AoESkillShotPosition.lua
ren "AoESkillShotPosition.lua" "AoE_SkillShot_Position.lua"
..\UI.bat  https://raw.githubusercontent.com/bolqqq/BoLScripts/master/common/AQLib.lua
..\UI.bat  https://raw.githubusercontent.com/Dienofail/BoL/master/common/BestCollision.lua
..\UI.bat  https://raw.githubusercontent.com/wquantum1/BoL/master/ChampionLib.lua
..\UI.bat  https://bitbucket.org/Klokje/public-klokjes-bol-scripts/raw/b891699e739f77f77fd428e74dec00b2a692fdef/Common/Collision.lua
..\UI.bat  https://raw.githubusercontent.com/SurfaceS/BoL_Studio/master/Scripts/Common/ComboClass.lua
..\UI.bat  https://raw.githubusercontent.com/LlamaBoL/BoL/master/Common/comboLib.lua
..\UI.bat  https://raw.githubusercontent.com/Superx321/BoL/master/common/CustomPermaShow.lua
..\UI.bat  https://raw.githubusercontent.com/BoL-Apple/BoL/master/Common/DataManager.lua
..\UI.bat  https://raw.githubusercontent.com/fter44/ilikeman/master/common/DRAW_POS_MANAGER.lua
..\UI.bat  https://raw.githubusercontent.com/fter44/ilikeman/master/common/Edited_AllClass.lua 
..\UI.bat  https://raw.githubusercontent.com/soulcaliber/BoL/master/Common/ezCollision.lua
..\UI.bat  https://raw.githubusercontent.com/soulcaliber/BoL/master/Common/ezLibrary.lua
..\UI.bat  https://bitbucket.org/boboben1/bol-scripts/raw/7dae5a6294b9db14b5430b72d9b5c2c6eb8758a1/Misc/FastCollision.lua
..\UI.bat  https://raw.githubusercontent.com/fter44/ilikeman/master/common/FTER_SOW.lua
..\UI.bat  http://iuser99.com/libraries/iLibraryENC.lua
..\UI.bat  http://scripts.imbeasty.com/ImBeastyLib.lua
..\UI.bat  https://bitbucket.org/Klokje/public-klokjes-bol-scripts/raw/master/Common/ImLib.lua
..\UI.bat  https://raw.githubusercontent.com/BoL-Apple/BoL/master/Common/iSAC.lua
..\UI.bat  https://raw.githubusercontent.com/fter44/ilikeman/master/common/ITEM_MANAGER.lua
..\UI.bat  https://raw.githubusercontent.com/fter44/ilikeman/master/common/LEVEL.lua
..\UI.bat  https://raw.githubusercontent.com/Dienofail/BoL/master/common/LineSkillShotPosition.lua
..\UI.bat  https://raw.githubusercontent.com/c3iL/BoL-1/master/MapPosition.lua
..\UI.bat  https://raw.githubusercontent.com/Dienofail/BoL/master/common/PPrediction.lua
..\UI.bat  https://bitbucket.org/Klokje/public-klokjes-bol-scripts/raw/master/Test/Prodiction/Prodiction.lua
..\UI.bat  https://raw.githubusercontent.com/UglyOldGuy/NintendoBoL/master/BH%20Bundle/Common/SALib.lua
..\UI.bat  http://iuser99.com/scripts/Selector.lua
..\UI.bat  https://raw.githubusercontent.com/Superx321/BoL/master/common/ShadowVayneLib.lua
..\UI.bat  https://raw.githubusercontent.com/gbilbao/Bilbao/master/BoL1/Common/SourceLib.lua
..\UI.bat  https://raw.githubusercontent.com/gbilbao/Bilbao/master/BoL1/Common/SOW.lua
..\UI.bat  https://raw.githubusercontent.com/SurfaceS/BoL_Studio/master/Scripts/Common/spellList.lua
..\UI.bat  https://raw.githubusercontent.com/Superx321/BoL/master/common/SxOrbWalk.lua
..\UI.bat  https://raw.githubusercontent.com/Ralphlol/BoLGit/master/VPrediction.lua
..\UI.bat  https://raw.githubusercontent.com/Yoooooo/YoLuaProject/master/YooLib.lua
..\UI.bat  https://raw.githubusercontent.com/Yoooooo/YoLuaProjects/master/Yolib.lua
REM Pastebin Links // Will only download the pastebin links as I add them, user may not always recieve the latest version of the library untill added.
..\UI.bat  http://pastebin.com/raw.php?i=hTM4bVC6
ren "raw.php?i=hTM4bVC6" "ItemRecipes.lua"
..\UI.bat  http://pastebin.com/raw.php?i=7EDjNzuq
ren "raw.php?i=7EDjNzuq" "spellDmg.lua"
..\UI.bat  http://pastebin.com/raw.php?i=UfZ0Efax
ren "raw.php?i=UfZ0Efax" "DrawDamageLib.lua"
REM Move all of the downloaded libraries into the Scripts\Common\ folder.
xcopy "*.lua" "../../Scripts/Common" /e /y /s /i
cd..
REM Remove the temporary directory which holds the libraries.
rmdir temp /q /s
cd..
cls

REM If VPrediction.lua in Scripts\Common doesn't exist goto error
if not exist Scripts\Common\VPrediction.lua goto error
REM If VPrediction.lua exists in Scripts\Common goto success
if exist Scripts\Common\VPrediction.lua goto success

:success
REM The script successfully found VPrediction.lua leading to this message being displayed.
echo Libraries have succesfully been installed. 
echo.
echo. ~ Exiting in 5 ~
ping 123.45.67.89 -n 1 -w 5000 > nul
exit

:error
REM The script couldn't find VPrediction.lua leading to this message being displayed.
echo An error has occured during the download and installation process.
echo.
echo Please ensure that the "Tools" folder is present within your BoL installation
echo If errors persist try and disable any anti-virus that may be installed.
echo The program will now exit . . .
ping 123.45.67.89 -n 1 -w 10000 > nul

UI.bat(在同一文件夹中)

@echo off
cls
echo Downloading and installing libraries (please be patient) . . .
set /p v=< ..\temp.txt
echo %v% downloaded of 40
wget --no-check-certificate -q %1
set /a v+=1
echo %v% > ..\temp.txt

我还没有测试过,但我愿意希望能奏效。

但我再次推荐简单而有效的解决方案 @echo on

刚刚改编自一个旧答案(还有更多不需要的代码!!)。 This answer 解释了基本思想。这个答案中的其余部分只是为了让它看起来更好看的大量代码,但当然不是必需的。

@echo off

    setlocal enableextensions disabledelayedexpansion

    for /l %%f in (0 1 100) do (
        call :drawProgressBar %%f "up test with a long text that will not fit on screen unless you have a lot of space"
    )
    for /l %%f in (100 -1 0) do (
        call :drawProgressBar %%f "going down test"
    )
    for /l %%f in (0 5 100) do (
        call :drawProgressBar !random! "random test"
    )

    rem Clean all after use
    call :finalizeProgressBar 1


    call :initProgressBar "|" " "
    call :drawProgressBar 0 "this is a custom progress bar"
    for /l %%f in (0 1 100) do (
        call :drawProgressBar %%f 
    )

    endlocal
    exit /b


:drawProgressBar value [text]
    if "%~1"=="" goto :eof
    if not defined pb.barArea call :initProgressBar
    setlocal enableextensions enabledelayedexpansion
    set /a "pb.value=%~1 %% 101", "pb.filled=pb.value*pb.barArea/100", "pb.dotted=pb.barArea-pb.filled", "pb.pct=1000+pb.value"
    set "pb.pct=%pb.pct:~-3%"
    if "%~2"=="" ( set "pb.text=" ) else ( 
        set "pb.text=%~2%pb.back%" 
        set "pb.text=!pb.text:~0,%pb.textArea%!"
    )
    <nul set /p "pb.prompt=[!pb.fill:~0,%pb.filled%!!pb.dots:~0,%pb.dotted%!][ %pb.pct% ] %pb.text%!pb.cr!"
    endlocal
    goto :eof

:initProgressBar [fillChar] [dotChar]
    if defined pb.cr call :finalizeProgressBar
    for /f %%a in ('copy "%~f0" nul /z') do set "pb.cr=%%a"
    if "%~1"=="" ( set "pb.fillChar=#" ) else ( set "pb.fillChar=%~1" )
    if "%~2"=="" ( set "pb.dotChar=." ) else ( set "pb.dotChar=%~2" )
    set "pb.console.columns="
    for /f "tokens=2 skip=4" %%f in ('mode con') do if not defined pb.console.columns set "pb.console.columns=%%f"
    set /a "pb.barArea=pb.console.columns/2-2", "pb.textArea=pb.barArea-9"
    set "pb.fill="
    setlocal enableextensions enabledelayedexpansion
    for /l %%p in (1 1 %pb.barArea%) do set "pb.fill=!pb.fill!%pb.fillChar%"
    set "pb.fill=!pb.fill:~0,%pb.barArea%!"
    set "pb.dots=!pb.fill:%pb.fillChar%=%pb.dotChar%!"
    set "pb.back=!pb.fill:~0,%pb.textArea%!
    set "pb.back=!pb.back:%pb.fillChar%= !"
    endlocal & set "pb.fill=%pb.fill%" & set "pb.dots=%pb.dots%" & set "pb.back=%pb.back%"
    goto :eof

:finalizeProgressBar [erase]
    if defined pb.cr (
        if not "%~1"=="" (
            setlocal enabledelayedexpansion
            set "pb.back="
            for /l %%p in (1 1 %pb.console.columns%) do set "pb.back=!pb.back! "
            <nul set /p "pb.prompt=!pb.cr!!pb.back:~1!!pb.cr!"
            endlocal
        )
    )
    for /f "tokens=1 delims==" %%v in ('set pb.') do set "%%v="
    goto :eof