0

I have wav files I am normalizing with ffmpeg-normalize (a python program). My batch file is this for %%n in (*.wav) do ffmpeg-normalize "%%n" -nt peak -t 0 -o "%%n-norm.wav"

In my directory of 5 files, I get 5 -norm.wav files. Unfortunately then, the batch file creates 5 -norm.wav-norm.wav files and so on and so on. Why wouldn't it stop at the original list of 5 files?

Compo
  • 36,585
  • 5
  • 27
  • 39
Core
  • 840
  • 11
  • 24

1 Answers1

1

I think the problem is that a standard for loop does not fully enumerate the target directory in advance (see also this related thread), and that the output files also match the pattern (*.wav) for the input files. The first issue could be solved by using a for /F loop that parses the output of the dir command, so the complete file list is generated before looping even starts; the second issue could be solved by an additional filter constituted by findstr to exclude output files to become reprocessed (when the script is executed more often than once):

for /F "eol=| delims=" %%F in ('
    dir /B /A:-D-H-S "*.wav" ^| findstr /V /I "-norm\.wav$"
') do (
    ffmpeg-normalize "%%F" -nt peak -t 0 -o "%%~nF-norm.wav"
)
aschipfl
  • 33,626
  • 12
  • 54
  • 99