同时批量处理多个文件 [英] Batch processing multiple files at the same time
问题描述
我有这个批处理命令
@echo off
FOR %%i in (C:\input\*.*) DO (
echo processing %%i
if not exist "C:\output\%%i" process.exe "%%i" -out "C:\output\%%i"
)
echo ---- finished ----
pause
在这里,我的工具process.exe
循环处理目录中的所有文件-如果结果尚不存在.
Here my tool process.exe
processes in a loop all files within a directory - if a result doesn't already exist.
现在我的CPU足够快,可以同时在2个或3个文件上运行此process.exe
,这将大大加快文件的处理速度.
Now my CPU is fast enough to run this process.exe
on 2 or 3 files at the same time which would make the processing of the files much faster.
问题:如何更改命令以使批处理文件同时处理2-3个文件?
Question: How do I have to change the command to make my batch file processing 2-3 files at the same time?
推荐答案
以下内容将启动进程,最大计数为%bunch%
.每当其中一个完成时,就会启动另一个.
The following starts processes up to a max count of %bunch%
. Whenever one of them finishes, another one will be started.
@ECHO off
setlocal enabledelayedexpansion
set bunch=3
for %%a in (C:\input\*) do (
call :loop
echo processing: %%a
start "MyCommand" cmd /c timeout 60
REM if not exist "C:\output\%%i" start "MyCommand" cmd /c process.exe "%%i" -out "C:\output\%%i"
)
call :loop
goto :eof
:loop REM waits for available slot
echo on
for /f %%x in ('tasklist /fi "windowtitle eq MyCommand" ^| find /c "cmd.exe"') do set x=%%x
if %x% geq %bunch% goto :loop
echo off
goto :eof
我没有您的process.exe
,所以我不得不猜测.但是REM
ed行应该适合您. (timeout
命令只是为了显示原理)
I don't have your process.exe
, so I have to guess. but the REM
ed line should work for you. (the timeout
command is just to show the princip)
这篇关于同时批量处理多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!