As JJ said, you can't do what you want within
a script. The script just goes from step to step.
But you can call outside processes.
The most flexible way to do something like that
is with an ActiveX EXE that can trigger events.
The WScript version of CreateObject can then be
used to create an event "sink":
WScript.CreateObject("Server1.Class1", "Sink1_")
If Server1.Class1 has an event like FileCopied
you can then trap it with
Sub Sink1_FileCopied()
That allows you to pass parameters to the event.
Designing your own ActiveX EXE allows for a very
luxurious design. But it does require writing a
component.
An easier way is something like the following:
Write a script like so and save it to the Desktop
as sleeper.vbs:
Arg = WScript.Arguments(0)
WScript.sleep Arg
MsgBox "Slept for " & CStr(arg \ 1000) & " seconds."
Then write another script to the Desktop like so:
Dim SH, i
Set SH = CreateObject("WScript.Shell")
For i = 1 to 3
SH.Run"sleeper.vbs " & 10000 * i
Next
Set SH = Nothing
If you then run script #2 it will run 3 instances of
sleeper.vbs, running 10, 20 and 30 seconds
respectively. The msgbox reports will confirm
that. So if you want to you could write a copy script
that keeps time and then either reports or, perhaps
better, writes a report to a log.
The following is "air code" and may not be the
best method, but it provides a general idea of how
you could do what you want. It's very sloppy,
though, needing to instantiate a new instance of
wscript for every file copy. Also, it might be tricky
to come up with a way to log it all. If every instance
opens a log file, writes, then closes the log, it's
possible there could be a traffic jam, with some
instances encountering a locked/open log file. Script
just isn't really the best tool for this job. It'd be better
if you can arrange it in such a way that you have time
to wait up to 2 seconds for each copy. Then you could
let one script handle the whole job.
Dim FSO, Arg, iTime
Arg = WScript.Arguments(0)
Set FSO = CreateObject("Scripting.FileSystemObject")
If FSO.FileExists(Arg) = True Then
Do
On Error Resume Next
FSO.CopyFile Arg, TheOtherPlace, True
If Err.Number = 0 Then
'quit loop and report file copied successfully.
Set FSO = Nothing
WScript.Quit
End If
WScript.sleep 100
iTime = iTime + 1
If iTime = 20 Then Exit Do
Loop
'-- if it got this far then copy failed
'-- And it's been about 2 seconds.
'-- report failure.