-2

I have a little batch file (see below) that does what the REM statement says.

When executed it displays each filename in turn as it's being processed (with a progress bar (of sorts) as the file is 're-written' to disk) but I would also like it to display a "counter" (starting at 1) that increments with each file processed so that when the final file is processed the counter will then display the total number of files that have been processed.

Is there any simple change I could make to achieve this? (I am not a coder, the batch file was given to me by someone else with whom I have lost contact.)

REM --ooOO  This adds c.365ms silence to all mp4 video files in the folder (adding 364 bytes to file size)  OOoo--

for %%a in (*.mp4) do mp4box "%%a" -add 0.2sSilenceM.mp3
pause
aschipfl
  • 33,626
  • 12
  • 54
  • 99

1 Answers1

0

To implement a counter is quite easy:

setlocal enabledelayedexpansion
set counter=0
for %%a in (*.mp4) do (
  set /a counter+=1
  echo processing file !counter!: %%a
  mp4box "%%a" -add 0.2sSilenceM.mp3
)
echo total processed files: %counter%

You need delayed expansion to use the counter inside the loop.

Stephan
  • 53,940
  • 10
  • 58
  • 91
  • Thank you very much , Stephan. That worked a treat! Thank you too for the referral to more details about "delayed expansion" (although most of that was **_way_** over my head. ) – Highlander Feb 08 '22 at 04:18
  • @Highlander please read, [What to do when someone answers my question.](https://stackoverflow.com/help/someone-answers) – Squashman Feb 08 '22 at 07:25
  • [This](https://stackoverflow.com/questions/4094699/how-does-the-windows-command-interpreter-cmd-exe-parse-scripts) explains the details (warning - your head may explode by reading it). But for now - accept that (unlike any other language) variables are replaced by their values *when the parser reads the (logical) line* (even before executing anything), while delayed expansion happens *during execution*. – Stephan Feb 08 '22 at 09:02