2015-08-25 92 views
0

好的,所以我有一个Windows 10 .bat脚本来将一个文件夹中的所有类型的视频转换为另一个使用多个命令的HandbrakeCLI输出。带有多个命令的Windows批处理脚本

除此之外,我想使用像BES这样的CPU使用率限制器来控制HandbrakeCLI的CPU使用率。

每个文件转换后,我想向我发送一个Pushbullet通知,说明转换已完成。

下面的代码可以帮助我实现这一点,然而我需要运行.bat文件两次才能启动,一次迭代后停止。

最初有问题使用多个命令,所以搜索和使用“&”之间的命令,没有喜悦。

我已经有了一个Powershell脚本来完成所有这些工作,所以请不要使用Powershell,我不想使用它,因为Powershell脚本需要提升特权,我不想再给它了。

FOR /R "D:\ToConvert" %%i IN (*.*) DO "C:\Program Files (x86)\BES_1.6.2\BES.exe" "C:\Program Files\Handbrake\HandBrakeCLI.exe" 33 --minimize & "C:\Program Files\HandBrake\HandBrakeCLI.exe" -i "%%i" -t 1 -c 1 -o "D:\Done\%%~ni.mp4" --preset="Normal" --optimize & powershell -ExecutionPolicy Bypass -command "D:\Scripts\SendPushBullet.ps1 "%%~ni" " Converted"" & taskkill /im BES.exe 

OR

call "C:\Program Files (x86)\BES_1.6.2\BES.exe" "C:\Program Files\Handbrake\HandBrakeCLI.exe" 33 --minimize 
for /r "D:\ToConvert" %%i IN (*) do (
"C:\Program Files\HandBrake\HandBrakeCLI.exe" -i "%%i" -o "D:\Done\%%~ni.mp4" --preset="Normal" --optimize 
powershell -ExecutionPolicy Bypass -command "D:\Scripts\SendPushBullet.ps1 "%%~ni" " Converted"" 
) 
taskkill /im BES.exe 
exit /b 

// TODO

删除已转换的文件

更新: 得到它使用代码工作然而下面现在要删除的文件转换从每个循环的“ToConvert”文件夹中删除

start "" "C:\Program Files (x86)\BES_1.6.2\BES.exe" "C:\Program Files\Handbrake\HandBrakeCLI.exe" 33 --minimize 
for /r "D:\ToConvert" %%i IN (*) do (
"C:\Program Files\HandBrake\HandBrakeCLI.exe" -i "%%i" -o "D:\Done\%%~ni.mp4" --preset="Normal" --optimize 
powershell -ExecutionPolicy Bypass -command "D:\Scripts\SendPushBullet.ps1 "%%~ni" " Converted"" 
) 
taskkill /im BES.exe 
+0

第二个选择对我来说很好。我只会把'FOR-DO'循环的右括号放在一个单独的行上。 – Melebius

回答

0

下面的代码工作;)

start "" "C:\Program Files (x86)\BES_1.6.2\BES.exe" "C:\Program Files\Handbrake\HandBrakeCLI.exe" 33 --minimize 
for /r "D:\ToConvert" %%i IN (*) do (
"C:\Program Files\HandBrake\HandBrakeCLI.exe" -i "%%i" -o "D:\Done\%%~ni.mp4" --preset="Normal" --optimize 
powershell -ExecutionPolicy Bypass -command "D:\Scripts\SendPushBullet.ps1 "%%~ni" " Converted"" 
) 
taskkill /im BES.exe 
del /f /q "D:\ToConvert\*.*" 
1

要从ToConvert中删除原始文件,只需在循环结尾添加del "%%i"即可。 的确,%%i保存了文件的绝对路径。

+0

谢谢!试了一下,但决定在完成转换后做一个完整的删除操作! –