I would assume that this methodology will serve you better:
@For /F "EOL=? Delims=" %%G In ('Dir /B /A:-D "*.mp4" ^| ^
"%__AppDir__%findstr.exe" /IR "\.mp4$" ^| ^
"%__AppDir__%findstr.exe" /IRV "\-small\.mp4$"'
) Do @If Not Exist "%%~nG-small%%~xG" (
ffmpeg.exe -i "%%G" -vcodec libx265 -crf 28 "%%~nG-small%%~xG"
If Not ErrorLevel 1 If Exist "%%~nG-small%%~xG" Del /A /F "%%G")
The idea is to get a directory listing of all files with an .mp4 extension. Using the first findstr to exclude any files which match the short, (8.3), names. It then pipes those through another findstr search, to exclude any of those files which already have -small appended to their basename. Next it checks to make sure that there are no existing files within that directory, with the same basename plus the -small basename suffix, (preventing possible overwrites). If all of those pass, ffmpeg.exe should be invoked, (subject to ffmpeg.exe being in the current directory, within %PATH%, or registered as executable with its location in the registry). Once the conversion has completed, the script checks the returned ErrorLevel was less than 1, (to ensure it was successful), and if so, whether the new file, (with the -small basename suffix) exists. If so it will proceed with the deletion, using the Del command.
If you wanted to try it again using conditional operators instead of the ErrorLevel, then it would look like this:
@For /F "EOL=? Delims=" %%G In ('Dir /B /A:-D "*.mp4" ^| ^
"%__AppDir__%findstr.exe" /IR "\.mp4$" ^| ^
"%__AppDir__%findstr.exe" /IRV "\-small\.mp4$"'
) Do @If Not Exist "%%~nG-small%%~xG" (
ffmpeg.exe -i "%%G" -vcodec libx265 -crf 28 "%%~nG-small%%~xG" && (
If Exist "%%~nG-small%%~xG" Del /A /F "%%G"))
DO (ffmpeg -i "%%i" -vcodec libx265 -crf 28 "%%~ni-small.mp4" && del "%%i")"%%~ni"-small.mp4to"%%~ni-small.mp4"…ffmpegsets its exit code to a non-zero value, hence&&does not execute the followingdelcommand; for testing I would temporarily use&instead of&&…