How to wait for a for loop to complete in a package before continuing?

Currently, I have a script package that I use to copy one large zip file from a network folder to several computers on the network. I need to make these copies in parallel, so I have a for loop that goes through the addresses and runs using robocopy. Here is what i have

for /F "tokens=*" %%A in (IPlist.txt) do ( start robocopy "\\networkfolder" \\%%A ) 

The problem is that I need to perform the extraction on all the machines that I just copied, but I need to wait for the robocopies to complete. I cannot use start / wait in a for loop since this destroys the parallel copy. Is there a way that I can make the script wait until all robocopies have finished? or an alternative solution?

FYI: I cannot extract from the network folder at first, since zip is a lot of small files and greatly slows down the transfer speed. When copying over a network, it should be one large file.

+4
source share
3 answers
 setlocal EnableDelayedExpansion set number=0 for /F "tokens=*" %%A in (IPlist.txt) do ( set /A number+=1 echo Flag > roboRunning.!number! start robocopy "\\networkfolder" \\%%A ^& del roboRunning.!number! ) :wait if exist roboRunning.* goto wait echo All robocopy processes have finished here 
+2
source

Here is the code I was using (syntax inside a batch file):

 SETLOCAL ENABLEDELAYEDEXPANSION set robocopycount=0 :loop for /F "usebackq" %%e IN (`tasklist /FI "IMAGENAME eq robocopy.exe"`) do if %%e==robocopy.exe set /A robocopycount=!robocopycount!+1 if %robocopycount% GEQ 1 goto continue rem goto loop :continue 

This actually counts the number of executable files that are launched right away, but can easily be adapted to check for availability. (In the case of this code, he checked that a certain number was executed.)

0
source
 SETLOCAL EnableDelayedExpansion SET num=0 FOR /F "tokens=*" %%A in (IPlist.txt) do ( SET /A num+=1 ECHO Flag > RoboRunNum.!num! START robocopy "\\networkfolder" \\%%A ^& del RoboRunNum.!num! ) :Check if exist RoboRunNum.* GOTO CHECK echo Robocopy Processes fave Finished 
0
source

Source: https://habr.com/ru/post/1487179/


All Articles