-1

I am having a list of variable which is 100 (a notepad file, MediaList.txt), but I want to do the execution in a span of 25, so what will be most easy way to do the same with the below mentioned loop. Basically I want to execute the below mentioned loop with the counter.

for /f %%I in (E:\MediaList.txt) do nsrjb -w -N %%I
aphoria
  • 19,796
  • 7
  • 64
  • 73
  • See ["Counter" in batch](http://stackoverflow.com/questions/15450163/) or any other topic found by running a Stack Overflow search with [\[batch-file\] counter](http://stackoverflow.com/search?q=%5Bbatch-file%5D+counter) as search string. – Mofi Apr 20 '15 at 17:46

1 Answers1

0
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET /a blocksize=23
FOR /f "tokens=1*delims=:" %%a IN ('findstr /n /r ".*" 100lines.txt') DO (
 SET /a progress=%%a %% %blocksize%
 IF !progress!==1 IF %%a neq 1 (
  REM pause here
  timeout /t 10
 )
 ECHO(nsrjb -w -N %%b
)

GOTO :EOF

For test purposes, I set the block size to 23, and use my standard 100-lines-of-text file 100lines.txt

How you want to pause the process is your own concern. I simply used a 10-second delay using timeout change to suit yourself.

The required nsrjb commands are merely ECHOed for testing purposes. After you've verified that the commands are correct, change ECHO(nsrjb to nsrjb to actually execute nsrjb.

It's simply a matter of numbering each line using findstr which prefixes each line with number:, then tokenising on first token=the number (%%a) and second token (%%b)=line-tail, using the colon as a delimiter.

From there, delyed-expansion is required to (calculate line-number mod block-size). If that result is 1, then we've processed a block of lines, so wait unless the line number is 1, which means we're about to process the very first line.

So - process a block (you choose the size), wait (you choose the time) for timeout or keypress; repeat until done.

The findstr command converts the line in the file from

u:\dir\file.txt

to, for instance

4:u:\dir\file.txt

The for command uses tokens = 1* and delims = :

Taking the delims first, what this means is "divide the line into tokens, using : as a separator"

So 4:u:\dir\file.txt would be split into 3 tokens, 4 u and \dir\file.txt.

If the tokens clause selected 1,2 and3 (tokens=1,2,3) then the token values 4 u and \dir\file.txt respectively would be assigned to %%a (the metavariable nominated in the for instruction, %%b and %%c respectively (incrementing alphabetical sequence).

The special token "number" * means `all of the line after the highest-nominated token number"

For "tokens=1*" then, two tokens are nominated (1 and *) so the first token value 4 is assigned to %%a and the remainder of the line past the token separator following the highest token number nominated (1) would be assigned to the next metavariable alphabetically (%%b) so u:\dir\file.txt is assigned to %%b

Magoo
  • 77,302
  • 8
  • 62
  • 84