Мне не удается заставить этот код работать после его изменения для приема нескольких аргументов. Я получаю "(было неожиданно в это время." Во втором для l oop. (Строка 23).
Любая идея, возможно ли иметь эти группы if внутри a for l oop? Из того, что я видел, это возможно.
Вместо группы if exist. Я мог бы просто использовать IF NOT EXIST, но я не знаю, как заставить его пропустить остальную часть кода в l oop для текущего элемента, но продолжайте для l oop для следующего элемента. Я не могу найти, как это сделать, и только нашел, как полностью выйти из l oop, что я не 'Не хочу этого делать.
@echo off
:variables
set script_dir="E:\Plex Scripts\DVR"
set script1=MCEBuddyScriptv2.bat
set method2=GPU
set script2=ScanMedia%method2%.ps1
set extension=mkv
set logfile=post_processing_log.txt
set history=history.txt
:change_directory
cd /d %script_dir%
:method
setlocal enabledelayedexpansion
:counter
set argCount=0
for %%x in (%*) do (
set /A argCount+=1
set "argVec[!argCount!]=%%~x"
)
::How many videos we will attempt to process
echo Number of files to process: %argCount%
:loop_start
for /L %%i in (1,1,%argCount%) do (
set fullpath=!argVec[%%i]!
::get new filepath (with new extension)
REM :names
for %%f in (!fullpath!) do set itemname=%%~nf
for %%f in (!fullpath!) do set newpath=%%~dpnf.%extension%
::if logfile doesn't exist then create it
REM :log_init
if not exist %logfile% echo This log file is a detailed history of the DVR Post Process scipt. >> %logfile%
if not exist %history% echo This is a history of the items processed with the DVR Post Process script. >> %history%
::check if input file exist
REM :check
if exist ( !fullpath! ) (
REM :script1
set state=Processing started
echo %date% - %time% - !state! for !itemname! with %script1% >> %logfile%
call %script1% !fullpath!
set state=Processing finished
echo %date% - %time% - !state! for !itemname! with %script1% >> %logfile%
REM :script2
set state=Processing started
echo %date% - %time% - !state! for !itemname! with %script2% >> %logfile%
powershell.exe -NoProfile -ExecutionPolicy Bypass -File %script2% -Path "!newpath!" -LimitCPU -AutoRepair -RemoveOriginal -RemoveRepaired -IAcceptResponsibility
set state=Processing finished
echo %date% - %time% - !state! for !itemname! with %script2% >> %logfile%
REM :log_final
echo %date% - %time% - Plex post processing script finished for !itemname!. The file will be moved and added to the library. >> %logfile%
echo. >> %logfile%
REM :history_final
echo %date% - %time% - !itemname! >> %history%
) else (
echo %date% - %time% - !itemname! does not exist. Error code 1. >> %logfile%
)
)
:end
exit /b 0
Редактировать: Получилось, чтобы заработало, убрав круглую скобку из «если существует (! полный путь!) ...»
Я не уверен почему это даже сработало изначально, прежде чем помещать внутрь for l oop. В любом случае, вот окончательный код.
@echo off
:variables
set script_dir="E:\Plex Scripts\DVR"
set script1=MCEBuddyScriptv2.bat
set method2=GPU
set script2=ScanMedia%method2%.ps1
set extension=mkv
set logfile=post_processing_log.txt
set history=history.txt
:change_directory
cd /d %script_dir%
:method
setlocal enabledelayedexpansion
:counter
set argCount=0
for %%x in (%*) do (
set /A argCount+=1
set "argVec[!argCount!]=%%~x"
)
::How many videos we will attempt to process
echo Number of files to process: %argCount%
:loop_start
for /L %%i in (1,1,%argCount%) do (
set fullpath="!argVec[%%i]!"
echo !fullpath!
::get new filepath (with new extension)
:names
for %%f in (!fullpath!) do set itemname=%%~nf
echo !itemname!
for %%f in (!fullpath!) do set newpath=%%~dpnf.%extension%
echo !newpath!
::if logfile doesn't exist then create it
:log_init
if not exist %logfile% echo This log file is a detailed history of the DVR Post Process scipt. >> %logfile%
if not exist %history% echo This is a history of the items processed with the DVR Post Process script. >> %history%
::check if input file exist
:check
if exist !fullpath! (
:script1
set state=Processing started
echo %date% - %time% - !state! for !itemname! with %script1% >> %logfile%
call %script1% !fullpath!
set state=Processing finished
echo %date% - %time% - !state! for !itemname! with %script1% >> %logfile%
:script2
set state=Processing started
echo %date% - %time% - !state! for !itemname! with %script2% >> %logfile%
powershell.exe -NoProfile -ExecutionPolicy Bypass -File %script2% -Path "!newpath!" -LimitCPU -AutoRepair -RemoveOriginal -RemoveRepaired -IAcceptResponsibility
set state=Processing finished
echo %date% - %time% - !state! for !itemname! with %script2% >> %logfile%
:log_final
echo %date% - %time% - Plex post processing script finished for !itemname!. The file will be moved and added to the library. >> %logfile%
echo. >> %logfile%
:history_final
echo %date% - %time% - !itemname! >> %history%
) else (
echo %date% - %time% - !itemname! does not exist. Error code 1. >> %logfile%
)
)
:end
exit /b 0