Search code examples
batch-filehandbrake

deleting the input file after handbraking in batch-file


I wrote this code for HandBrakeCLI as a batch file to manipulate my videos. This code creates output files with input file name plus a "_conv" suffix.

for /R .\test %%F in (*.mov) do HandBrakeCLI -e x264 --x264-preset medium -q 35 --crop 0:0:0:0 --aencoder copy -i "%%~fF" -o "%%~pF%%~nF_conv.mp4

Then I want to delete the original file and then remove _conv part of the output file. What should be added to the code above?

I want to delete each file just after converting it, or at least when going from its containing folder to another folder, not wholly after converting all of the file (because lots of files must be converted and I may run out of space)

By the way, how can I add other formats in addition of *.mov in the code?


Solution

  • for /R .\test %%F in (*.mov) do (
        HandBrakeCLI -e x264 --x264-preset medium -q 35 --crop 0:0:0:0 --aencoder copy -i "%%~fF" -o "%%~dpF%%~nF_conv.mp4"
        if exist "%%~dpF%%~nF_conv.mp4" (
            del "%%~fF"
            ren "%%~dpF%%~nF_conv.mp4" "%%~nxF"
        )
    )
    

    All the information is inside your original code. All that is needed is to wrap the set of commands in parenthesis so the three commands are executed for each of the input files. Also, an aditional if has been included to only delete the source file if the converted file exists.