I have a batch file that recursively encodes videos to a sub folder "encode" then deletes the original and moves the new file to the original directory. The problem I'm having is that after each video is encoded, the for loop picks up the newly encoded video and runs again. After that, it moves on to the next video. I'm not sure why it runs twice instead of once or infinitely. What am I misunderstanding? I am a complete novice, so my apologies if it's a simple mistake.
@echo off
set /A count = 0
pushd %~dp0
for /R %%f in (*.mp2, *.mpg, *.vob, *.avi, *.wmv, *.mov, *.mp4, *.m4v, *.mpeg) do (
mkdir %%~dpf\encode
C:\HandBrakeCLI -i "%%f" -o "%%~dpf\encode%%~nf.mp4"
del "%%f"
move "%%~dpf\encode\%%~nf.mp4" %%~dpf
rmdir %%~dpf\encode
set /A count+=1
)
popd
echo Count is: %count%
pause