Batch File - Wait before Looping

I created a batch file several months ago, which I cannot find, and now cannot remember how I made it.

I want to copy files to another drive, and then pause for 20 seconds or so, then do it again.

I'm testing the controller of an external drive that I have.  After about a day, the old drive controller dropped out.  I now have a replacement for it, and i'm trying to test it again.  Only problem is that I can't find the batch file.

I know that i didn't use the sleep or ping functions, and don't want to in this iteration either.

I've been using xcopy for some time, but I suppose I should start using the robocopy command instead, so I would prefer that the solution makes use of the robocopy command.  Please explain any necessary switches and syntax.

fl4ianAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Steve KnightIT ConsultancyCommented:
Without using ping command there are few solutions to waiting 20 seconds built in.  any particualr reason for not using it?

@echo off
set source=C:\source\*.*
set dest=D:\dest
:next
 xcopy /e "%source% "%dest%"
rem or use robocopy /e "%source% "%dest%"
 ping -n 20 127.0.0.1
goto next
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Steve KnightIT ConsultancyCommented:
I've got a little time-waiting program on my website too I wrote ages ago.  There is source there and an EXE:

http://www.dragon-it.co.uk/links/info.htm

You can also use VBScript and call this from a on-the-fly created VBScript file, e.g.

@echo off
echo wscript.sleep wscript.Arguments.Item(0) * 1000> "%temp%\sleep1.vbs"
echo Time is %time%
cscript "%temp%\sleep1.vbs" //nologo 10
echo Time is %time%

which will pause for 10 seconds, so for your program you'd need

@echo off
set source=C:\source\*.*
set dest=D:\dest
echo wscript.sleep wscript.Arguments.Item(0) * 1000> "%temp%\sleep1.vbs"
:next
 xcopy /e "%source% "%dest%"
rem or use robocopy /e "%source% "%dest%"
 cscript "%temp%\sleep1.vbs" //nologo 10
 goto next
0
fl4ianAuthor Commented:
thanks, dragon.

I had to add the  - i switch to ping to get it to wait the time, the - n was firing as soon as it came back.  here's what ended up working for me, and giving me somewhere a little more than 30 seconds (but not 39 as it indicates):

rem @echo off
:next
 xcopy c:\KAV k:\KAV /ECHYIV
 xcopy f:\SP4 k:\SP4 /ECHYIV
 ping -n 39 -i 2 127.0.0.1
 rem pause
goto next

thanks, again.
0
fl4ianAuthor Commented:
thanks, again.
0
Steve KnightIT ConsultancyCommented:
Yeah it's never a perfect pause ... but it does work, sometimes can work better if you ping a non-existent address instead.  Thanks for the grade anyway.

Steve
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.