|
| |||||||||
| Tags: batch, create, dos, loop, script |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| 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 |
|
#2
| |||
| |||
| 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. |
|
#3
| |||
| |||
| 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. > |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "How to create a script in a DOS batch file to do a loop?" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Multiple commands in batch file loop | mrgou | Vista Help | 9 | 26-04-2011 09:04 PM |
| Batch file loop problems | rickylakhay | Vista Help | 1 | 29-11-2010 10:46 PM |
| Batch Script Text file parse | tator.usenet@gmail.com | Windows Server Help | 5 | 25-03-2009 03:12 AM |
| Multiple commands for a batch file in a for loop? | SANDESH49 | Software Development | 2 | 17-02-2009 07:03 PM |
| How can I play a Wav file from batch/cmd script? | hbfavor | Windows Vista Performance | 7 | 13-09-2008 10:21 PM |