2

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)

Community
  • 1
  • 1
jediotic
  • 23
  • 1
  • 1
  • 5
  • inside your for-loop use `echo !counter! / %TotalCount%`. `%counter%` will not be updated in the loop; `!counter!` will. - and is it "count" or "counter"? (probably a typo) – Stephan Nov 29 '13 at 21:42
  • (thanks for the reply Stephan) Just tried !counter! instead of %counter% and it actually has the same result. 1 in every line – jediotic Nov 29 '13 at 21:47
  • 1
    you did a `set /a count` and echo `countER` – Stephan Nov 29 '13 at 21:48
  • what a mistake! Thank you very much - it works now! :) btw: you wouldnt happen to know 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)? – jediotic Nov 29 '13 at 22:13
  • take a look here: http://stackoverflow.com/questions/17240681/progress-bar-in-batch-string-manipulation (just leave out the "bar"-parts) – Stephan Nov 29 '13 at 22:37

2 Answers2

2

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
)
foxidrive
  • 40,353
  • 10
  • 53
  • 68
-1

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

Community
  • 1
  • 1
Stephan
  • 53,940
  • 10
  • 58
  • 91