Results 1 to 3 of 3

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

  1. #1
    Jon Osborn Guest

    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. #2
    Pegasus \(MVP\) Guest

    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. #3
    Jon Osborn Guest

    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.
    >




Similar Threads

  1. Multiple commands for a batch file in a for loop?
    By SANDESH49 in forum Software Development
    Replies: 4
    Last Post: 08-05-2012, 10:40 AM
  2. Multiple commands in batch file loop
    By Toshaan in forum Vista Help
    Replies: 10
    Last Post: 08-05-2012, 10:39 AM
  3. Windows Batch script to read file
    By SinghR in forum Windows Server Help
    Replies: 1
    Last Post: 28-04-2012, 12:56 PM
  4. batch script to find a file
    By stevenwhite in forum Software Development
    Replies: 1
    Last Post: 10-04-2012, 12:55 PM
  5. How can I play a Wav file from batch/cmd script?
    By NaFula in forum Windows Vista Performance
    Replies: 3
    Last Post: 13-09-2008, 09:21 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,665,838.40538 seconds with 17 queries