@echo off
setlocal enabledelayedexpansion
for %%a in (*.*) do (
set /a "pre+=1
)
for /f %%a in ('call :star') do (
set /a "count=count+10000"
set /a "fi=10000/pre"
set /a "en=!fi!*!count!"
set "br=!en:~0,-6!"
title !br!
)
pause
:star
echo Some stuff.
echo Some more.
exit /b
我正在尝试创建一个在命令运行时更新的进度条。 一切运行良好,除了我需要能够在 for 命令中使用 call 命令,而我当前的设置(如下)不工作。
如何在 for 循环中使用 call 命令?
最佳答案
无法直接调用已处理项目的子程序。
但是可以用这个 Aacini's trick 来解决这个问题:
@echo off
if /I "%1" equ "call" shift & shift & goto %2
setlocal enabledelayedexpansion
for %%a in (*.*) do (
set /a "pre+=1
)
for /f %%a in ('%0 call :star') do (
set /a "count=count+10000"
set /a "fi=10000/pre"
set /a "en=!fi!*!count!"
set "br=!en:~0,-6!"
title !br!
)
pause
exit /b %errorlevel%
:star
echo Some stuff.
echo Some more.
exit /b
你需要这条线 if /I "%1" equ "call" shift & shift & goto %2
在脚本的开头,然后您可以使用 %0 call :start
调用子例程形成 for 循环。
关于windows - 如何从 `for` 处理的项目(在 `in` 之后)调用子程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33447356/