Reputation: 23
I'm using these functions in a BATCH-File:
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
I searched for a way to add a counter* to the last function, so it will tell me in the Commandbox about the progress, but all I found was a "standalone" function like this:
setlocal enableextensions enabledelayedexpansion
SET /A COUNT=1
FOR /F "tokens=*" %%A IN (config.properties) DO (
SET /A COUNT+=1
ECHO !COUNT!
)
endlocal
(Can be found here: Counting in a FOR loop using Windows Batch script)
Can you tell me how to add the 2nd function (counter) into the 1st (firefox-tab-opening)?
*= I mean that everytime the for-Function is opening a new Tab in Firefox, the batch puts a count in the cmd.exe-Box (preferably in the same line as some kind of a overwrite instead of a new line for every count) with the total amount of lines (%Count%) behind it (like 23 / 80, when the new Tab has opened 24 / 80 and so on)
Thank you very much for your precious time in helping me :)
EDIT: Thought I'll share my complete non-working version:
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
)
Problem: It gives out "1 / %TotalCount%" all the time! (%TotalCount% works fine)
Upvotes: 2
Views: 13434
Reputation: 56155
how I can make the "new" !counter! overwrite the old !counter! (so it stays in the same line, and not a new line every time)?
@echo off
setlocal EnableDelayedExpansion
for /f %%a in ('copy /Z "%~dpf0" nul') do set "CR=%%a"
for /l %%n in (1,1,10000) do (
set /P "=Count %%n /10000!CR!" <nul
)
based on (well, basically copied from) user jeb from here: Echoing in the same line
Upvotes: -1
Reputation: 41224
The enabledelayedexpansion
is required to echo variables in a loop, and the cls
is the usual simple method to update a screen with a static number.
@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
)
Upvotes: 2