在修改该代码以接受多个参数后,我无法使此代码正常工作。我在第二个for循环中收到“(这是意外的时刻。”(第23行)。
知道在for循环中是否有这些if组吗?从我所看到的可能。
而不是如果存在的组。我可以只使用IF NOT EXIST,但是我不知道如何跳过当前项目循环中的其余代码,而继续进行下一个项目的循环。我找不到方法,只能找到我不想做的完全退出循环的方法。
@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
编辑:通过除去“如果存在(!fullpath!)...”中的括号使它正常工作。
我不确定为什么在放入for循环之前,即使最初也能正常工作。无论如何,这是最终代码。
@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
在修改该代码以接受多个参数后,我无法使此代码正常工作。我在第二个for循环中得到“(这是意外的。”(第23行)。任何想法,甚至...
if /?