<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; VBScript: слежение за содержимым каталога]]></title>
	<link rel="self" href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=754&amp;type=atom" />
	<updated>2007-10-06T12:06:15Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.script-coding.com/viewtopic.php?id=754</id>
		<entry>
			<title type="html"><![CDATA[VBScript: слежение за содержимым каталога]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=5363#p5363" />
			<content type="html"><![CDATA[<p>Автор идеи - <strong>Alexbootch</strong>.<br />Пример скрипта, который отслеживает удаление файлов с указанным расширением в указанном каталоге:<br /></p><div class="codebox"><pre><code>strDrive = &quot;C:&quot;
strDir = &quot;\\Temp\\&quot;
strExt = &quot;png&quot;
strComputer = &quot;.&quot;
&#039;===================================================================
Set objWMIService = GetObject(&quot;winmgmts:\\&quot; &amp; strComputer &amp; &quot;\root\CIMv2&quot;) 
Set objEvents = objWMIService.ExecNotificationQuery _
(&quot;SELECT * FROM __InstanceDeletionEvent WITHIN 5 WHERE &quot; &amp; _
    &quot;TargetInstance ISA &#039;CIM_DataFile&#039;&quot; &amp; _
    &quot; AND TargetInstance.Extension = &#039;&quot; &amp; strExt &amp; &quot;&#039;&quot; &amp; _
    &quot; AND TargetInstance.Drive = &#039;&quot; &amp; strDrive &amp; &quot;&#039;&quot; &amp; _
    &quot; AND TargetInstance.Path = &#039;&quot; &amp; strDir &amp; &quot;&#039;&quot;)

Do While(True)
    Set objReceivedEvent = objEvents.NextEvent
    WScript.Echo Now &amp; &quot; &quot; &amp; objReceivedEvent.TargetInstance.Name
Loop</code></pre></div><p>Фильтр по расширению можно убрать из WMI-запроса и отслеживать таким образом все файлы. Кроме того, можно отслеживать модификацию и создание файлов, используя классы <strong>__InstanceCreationEvent</strong> и <strong>__InstanceModificationEvent</strong> полностью аналогично.<br />Примечание: отслеживание вложенных каталогов в данном случае проблематично, т.к. оператор <strong>LIKE</strong> со свойством <strong>Path</strong> в WMI-запросе, похоже, корректно не работает. Если у вас есть идеи, создайте новую тему в разделе <a href="http://forum.script-coding.com/viewforum.php?id=1">Разработка скриптов</a> со ссылкой на тему, которую вы сейчас читаете.</p>]]></content>
			<author>
				<name><![CDATA[The gray Cardinal]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=2</uri>
			</author>
			<updated>2007-10-06T12:06:15Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=5363#p5363</id>
		</entry>
</feed>
