1

I've found the code to check a file for errors and it creates a log file with the contents. Is there a way to alter it and rename a file that has errors but not the ones without?

@echo off

set "filtro=%1"
if [%filtro%]==[] (
    set "filtro=*.mp4"
    )

for /R %%a in (%filtro%) do call :doWork "%%a"

    PAUSE
    exit /B

:doWork
    "F:\- error check\ffmpeg.exe" -v error -i %1 -f null - > "%~1.log" 2>&1
llogan
  • 59,497
Teh
  • 13

1 Answers1

1

1) Try using delayed expansion for your variables:

setlocal enabledelayedexpansion

2) Verify if some extension (%~x1) was provided in argument:

if /i "%~x1"=="" (set "_filtro=.mp4") else set "_filtro=%~x1"

3) Use For /F and Where.exe /R loop command, where you can recursively list/process your files:

for /f "tokens=* delims= " %%i in ('%__APPDIR__%where.exe /r . "*!_filtro!"'

4) Take advantage of the operator ||, for to rename any file that has an error:

"!_ffmpeg!" -i "%%~i" -v error -f null - || ren "%%~i" "%%~ni_ERROR_%%~xi"

5) Use Clip command for copy your log file content to your ClipBoard/Crtl+C:

type .\error.log|"%__APPDIR__%clip.exe"

6) If you prefer, you can also replace Pause to Timeout.exe, and/or, exit /b to goto :EOF:

"%__APPDIR__%timeout.exe" /t -1 & endlocal & goto :EOF

@echo off && setlocal enabledelayedexpansion

echo\ & cd/d "%~dp0" && >nul cd.>.\error.log

set "_ffmpeg=F:\- error check\ffmpeg.exe"
if /i "%~x1"=="" (set "_filtro=.mp4") else set "_filtro=%~x1"

echo\Filtro: ..\*!_filtro! && for /f "tokens=* delims= " %%i in ('%__APPDIR__%where.exe /r . "*!_filtro!"'
)do echo\%%~i && 2>>error.log ("!_ffmpeg!" -i "%%~i" -v error -f null - || ren "%%~i" "%%~ni_ERROR_%%~xi")

type error.log | "%__APPDIR__%clip.exe" & "%__APPDIR__%timeout.exe" /t -1 & endlocal & goto :EOF

  • Same code in compacted formatting:
@echo off && setlocal enabledelayedexpansion && echo\ & cd/d "%~dp0" & >nul cd.>.\error.log

set "_ffmpeg=F:\- error check\ffmpeg.exe" && if /i "%~x1"=="" (set "_filtro=.mp4") else set "_filtro=%~x1"
echo\Filtro: ..\*!_filtro! && for /f "tokens=* delims= " %%i in ('%__APPDIR__%where.exe /r . "*!_filtro!"'
)do echo\%%~i && 2>>error.log ("!_ffmpeg!" -i "%%~i" -v error -f null - || ren "%%~i" "%%~ni_ERROR_%%~xi")
echo/ && type .\error.log|"%__APPDIR__%clip.exe" & "%__APPDIR__%timeout.exe" /t -1 & endlocal & goto :EOF

For command line help, you can use /?:

Ren /?, For /?,Where /?, Endlocal /?, Goto /?, Timeout /?, SetLocal /?, if /?

On the internet, you can get more help on:

Io-oI
  • 8,193
  • Hey, this is way over my head, but i'll try it out. Thank you very much for taking the time. – Teh Mar 29 '20 at 19:42