![]() |
How to create a script in a DOS batch file to do a loop? We are copy some files with a batch on a win2k3 server, but some files can't be copied over becuase they are in use for about 3 minutes. When it is not in use it can be copied over. So I have created a batch that looks like this: copy /y c:\folder1\file1.avi c:\folder2\file1.avi copy /y c:\folder1\file2.avi c:\folder2\file2.avi sleep 60 copy /y c:\folder1\file1.avi c:\folder2\file1.avi copy /y c:\folder1\file2.avi c:\folder2\file2.avi sleep 60 copy /y c:\folder1\file1.avi c:\folder2\file1.avi copy /y c:\folder1\file2.avi c:\folder2\file2.avi sleep 60 copy /y c:\folder1\file1.avi c:\folder2\file1.avi copy /y c:\folder1\file2.avi c:\folder2\file2.avi sleep 60 Sleep is a program for the resket that cause the program to pause for 60 seconds. There are more than two files but I figured this would be enough for the excample. Since each file is 3 minutes long I know the file gets over written within the 4 atemps. I know DOS has a FOR loop but I read though the help and could not fivure it out. I know this is proably simple but I am just not getting it. Thanks, Jon |
Re: How to create a script in a DOS batch file to do a loop? "Jon Osborn" <josborn@pcsii.com> wrote in message news:u2ADyGRvIHA.5288@TK2MSFTNGP06.phx.gbl... > We are copy some files with a batch on a win2k3 server, but some files > can't be copied over becuase they are in use for about 3 minutes. When it > is not in use it can be copied over. So I have created a batch that > looks like this: > > copy /y c:\folder1\file1.avi c:\folder2\file1.avi > copy /y c:\folder1\file2.avi c:\folder2\file2.avi > sleep 60 > copy /y c:\folder1\file1.avi c:\folder2\file1.avi > copy /y c:\folder1\file2.avi c:\folder2\file2.avi > sleep 60 > copy /y c:\folder1\file1.avi c:\folder2\file1.avi > copy /y c:\folder1\file2.avi c:\folder2\file2.avi > sleep 60 > copy /y c:\folder1\file1.avi c:\folder2\file1.avi > copy /y c:\folder1\file2.avi c:\folder2\file2.avi > sleep 60 > > Sleep is a program for the resket that cause the program to pause for 60 > seconds. There are more than two files but I figured this would be enough > for the excample. Since each file is 3 minutes long I know the file gets > over written within the 4 atemps. I know DOS has a FOR loop but I read > though the help and could not fivure it out. I know this is proably > simple but I am just not getting it. > > Thanks, > Jon Try this: @echo off for /L %%a in (1,1,10) do ( xcopy /d /y /c c:\folder1\file1.avi c:\folder2\ xcopy /d /y /c c:\folder1\file2.avi c:\folder2\ ping localhost -n 60 > nul ) This version will attempt the copy process ten times, with a pause of about one minute in between. Files that are already up-to-date won't be copied a second time. Locked files won't cause the batch file to hang. |
Re: How to create a script in a DOS batch file to do a loop? thanks Jon "Pegasus (MVP)" <I.can@fly.com.oz> wrote in message news:eKWvPMRvIHA.4492@TK2MSFTNGP02.phx.gbl... > > "Jon Osborn" <josborn@pcsii.com> wrote in message > news:u2ADyGRvIHA.5288@TK2MSFTNGP06.phx.gbl... >> We are copy some files with a batch on a win2k3 server, but some files >> can't be copied over becuase they are in use for about 3 minutes. When >> it is not in use it can be copied over. So I have created a batch that >> looks like this: >> >> copy /y c:\folder1\file1.avi c:\folder2\file1.avi >> copy /y c:\folder1\file2.avi c:\folder2\file2.avi >> sleep 60 >> copy /y c:\folder1\file1.avi c:\folder2\file1.avi >> copy /y c:\folder1\file2.avi c:\folder2\file2.avi >> sleep 60 >> copy /y c:\folder1\file1.avi c:\folder2\file1.avi >> copy /y c:\folder1\file2.avi c:\folder2\file2.avi >> sleep 60 >> copy /y c:\folder1\file1.avi c:\folder2\file1.avi >> copy /y c:\folder1\file2.avi c:\folder2\file2.avi >> sleep 60 >> >> Sleep is a program for the resket that cause the program to pause for 60 >> seconds. There are more than two files but I figured this would be >> enough for the excample. Since each file is 3 minutes long I know the >> file gets over written within the 4 atemps. I know DOS has a FOR loop >> but I read though the help and could not fivure it out. I know this is >> proably simple but I am just not getting it. >> >> Thanks, >> Jon > > Try this: > @echo off > for /L %%a in (1,1,10) do ( > xcopy /d /y /c c:\folder1\file1.avi c:\folder2\ > xcopy /d /y /c c:\folder1\file2.avi c:\folder2\ > ping localhost -n 60 > nul > ) > > This version will attempt the copy process ten times, with > a pause of about one minute in between. Files that are > already up-to-date won't be copied a second time. Locked > files won't cause the batch file to hang. > |
All times are GMT +5.5. The time now is 11:36 AM. |