property WaitForDirectoryChangeNotification.
Watches any change within a directory (aka
subdirectories and files changes)
This property is useful for monitoring any change into
a directory and its subtrees, so a trigger program
can start accordingly with this notification.
|
dirName
[in] . Full
directory name (e.g c:\windows)
NotificationHandle
[in,defaultvalue(0)]
. 0 if first call of the property which instantiates and initializes the
handle of change.
. Handle value if subsequent calls
freeNotificationHandle
[in,defaultvalue(0)]
. 0 or geater if reuse the handle.
The value will then be used as a
timeout in seconds to wait and yield control to client code.
(if 0
the timeout will be 15 seconds)
. -1 to free the handle and close the notification.
pVal
[out, retval]
The returned value is a handle of change notification for the directory
if any change happened.
For the second and subsequent
calls, the value 0 means the timeout without any changes
found into the
directory.
Example of a ready-to-use scenario:
Const
targetDirectory = "C:\APIDev"
Dim
changeCounter
Dim
ScriptEZ
Main()
Sub Main()
Set ScriptEZ = WScript.CreateObject("ScriptEZ.API","ScriptEZ_")
ScriptEZ.AppRegister
changeCounter = 0
notificationHandle
= ScriptEZ.WaitForDirectoryChangeNotification(targetDirectory,0,0)
If notificationHandle > 0 Then
hThreadPool =
ScriptEZ.CreateTaskQueueObject(1)
r = ScriptEZ.AddTask(hThreadPool,notificationHandle)
End If
Do while (true)
Wscript.Sleep 1000
Loop
End Sub
Function ScriptEZ_onRun(localStorage)
'-- Waiting and yielding control every 7 seconds
r = ScriptEZ.WaitForDirectoryChangeNotification("",localStorage,7)
If r > 0 And
changeCounter = 0 Then
ScriptEZ.Echo CStr(Time)
+ " - onChange : " + CStr(changeCounter)
changeCounter =
1
ElseIf r = 0 And changeCounter > 0 Then
ScriptEZ.Echo CStr(Time)
+ " - Changes occurred into "
+ targetDirectory + _
" => triggering a program"
'--running
a program here...
changeCounter
= 0
End If
ScriptEZ_onRun = CLng(1)
'--running again and again
End Function
S_OK
The operation was successfull.
E_POINTER
A NULL pointer was supplied as an argument.
E_UNEXPECTED
An unexpected error occoured.