• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1547
  • Last Modified:

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.

0
fl4ian
Asked:
fl4ian
  • 3
  • 2
1 Solution
 
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
 
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now