Qwertz
Qwertz

Reputation: 1

Condition after for loop (Batch/CMD)

So I currently have this batch that converts every .MTS on the current folder to .MP4 using ffmpeg, however when it is done I get both .mp4 and .mts on the folder. I have 2 batches, one to convert the files and another one to delete the unwanted files afterwards, but I'm having trouble trying to join them in the same batch script.

Converter.bat:

for %%i in (*.MTS) do ffmpeg -i "%%i" -c:a libfdk_aac -b:a 256k "%%~ni.mp4"

Delete.bat:

del /S *.MTS

Any help please?

Upvotes: 0

Views: 37

Answers (1)

Stephan
Stephan

Reputation: 56155

to "join them in a batch script", just write them into the same batch script:

@echo off
for %%i in (*.MTS) do ffmpeg -i "%%i" -c:a libfdk_aac -b:a 256k "%%~ni.mp4"
del /S *.MTS

Although I would recommend:

@echo off
for %%i in (*.MTS) do ffmpeg -i "%%i" -c:a libfdk_aac -b:a 256k "%%~ni.mp4" && del /S "%%i"

&& means "do the following only if the previous was successful", so the file will only be deleted, when the conversion was successful.

(reconsider del /s - it will delete the file in the current folder and all subfolders. A simple del "%%i" will only delete the processed file and keep files in any subfolders)

Upvotes: 1

Related Questions