Go Back   TechArena Community > Technical Support > Computer Help > Windows Server > Windows Server Help
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



How to create a script in a DOS batch file to do a loop?

Windows Server Help


Reply
 
Thread Tools Search this Thread
  #1  
Old 24-05-2008
Jon Osborn
 
Posts: n/a
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



Reply With Quote
  #2  
Old 24-05-2008
Pegasus \(MVP\)
 
Posts: n/a
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.


Reply With Quote
  #3  
Old 27-05-2008
Jon Osborn
 
Posts: n/a
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.
>



Reply With Quote
Reply

  TechArena Community > Technical Support > Computer Help > Windows Server > Windows Server Help
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


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 for a batch file in a for loop? SANDESH49 Software Development 4 08-05-2012 10:40 AM
Multiple commands in batch file loop Toshaan Vista Help 10 08-05-2012 10:39 AM
Windows Batch script to read file SinghR Windows Server Help 1 28-04-2012 12:56 PM
batch script to find a file stevenwhite Software Development 1 10-04-2012 12:55 PM
How can I play a Wav file from batch/cmd script? NaFula Windows Vista Performance 3 13-09-2008 09:21 PM


All times are GMT +5.5. The time now is 10:12 AM.