<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; VBScript: слежение за содержимым каталога]]></title>
		<link>http://forum.script-coding.com/viewtopic.php?id=754</link>
		<atom:link href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=754&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «VBScript: слежение за содержимым каталога».]]></description>
		<lastBuildDate>Sat, 06 Oct 2007 12:06:15 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[VBScript: слежение за содержимым каталога]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=5363#p5363</link>
			<description><![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>]]></description>
			<author><![CDATA[null@example.com (The gray Cardinal)]]></author>
			<pubDate>Sat, 06 Oct 2007 12:06:15 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=5363#p5363</guid>
		</item>
	</channel>
</rss>
