gpt4 book ai didi

windows - BATCH - 向函数添加计数器(for/loop)

转载 作者:可可西里 更新时间:2023-11-01 10:46:58 26 4
gpt4 key购买 nike

我在 BATCH 文件中使用这些函数:

set /p time="Enter seconds  "

for /f %%C in ('Find /V /C "" ^< list.txt') do set Count=%%C

for /f "usebackq delims=" %%i in ("list.txt") do (
start "" "firefox.exe" -new-tab "http://www.website.com/%%i"
>nul ping -n %time% localhost

我搜索了一种向最后一个函数添加 counter* 的方法,这样它会在 Commandbox 中告诉我进度,但我发现的只是一个像这样的“独立”函数:

setlocal enableextensions enabledelayedexpansion
SET /A COUNT=1
FOR /F "tokens=*" %%A IN (config.properties) DO (
SET /A COUNT+=1
ECHO !COUNT!
)
endlocal

(可在此处找到:Counting in a FOR loop using Windows Batch script)

你能告诉我如何将第二个功能(计数器)添加到第一个功能(firefox-tab-opening)中吗?

*= 我的意思是,每次 for-Function 在 Firefox 中打开一个新标签时,批处理都会在 cmd.exe-Box 中添加一个计数(最好与某种覆盖在同一行而不是换行对于每个计数)以及它后面的总行数(%Count%)(比如 23/80,当新标签打开时 24/80 等等)

非常感谢您抽出宝贵时间帮助我:)

编辑:我想分享我的完整的非工作版本:

for /f %%C in ('Find /V /C "" ^< list.txt') do set TotalCount=%%C
ECHO (List with %TotalCount% Lines)

set /p time="Enter seconds "



set /a counter=1

for /f "usebackq delims=" %%i in ("list.txt") do (
start "" "firefox.exe" -new-tab "http://www.website.com/%%i"

set /a count+=1
echo %counter% / %TotalCount%

>nul ping -n %time% localhost


)

问题:它一直给出“1/%TotalCount%”! (%TotalCount% 工作正常)

最佳答案

enabledelayedexpansion 需要在循环中回显变量,cls 是用静态数字更新屏幕的常用简单方法。

@echo off
setlocal enabledelayedexpansion
for /f %%C in ('Find /V /C "" ^< list.txt') do set TotalCount=%%C
ECHO (List with %TotalCount% Lines)

set /p time="Enter seconds "
set /a counter=0

for /f "usebackq delims=" %%i in ("list.txt") do (
start "" "firefox.exe" -new-tab "http://www.website.com/%%i"
cls
set /a counter+=1
echo !counter! / !TotalCount!
>nul ping -n %time% localhost
)

关于windows - BATCH - 向函数添加计数器(for/loop),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20293129/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com