Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Checking for File Extension

32 views
Skip to first unread message

ewm

unread,
Nov 11, 2009, 7:24:08 PM11/11/09
to

I am writing a SSIS package (SQL2005) and need to watch a folder for the
appearance of a text file. I am using the WMI Event Watcher task. This WQL
code will correctly monitor for any file coming into the folder:

SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE TargetInstance ISA
"CIM_DirectoryContainsFile" and TargetInstance.GroupComponent=
"Win32_Directory.Name=\"c:\\\\ReceiveQueue\""

I thought that I could add teh TargetInstance.Extension to the WQL query
like this:

SELECT * FROM __InstanceCreationEvent WITHIN 10 WHERE TargetInstance ISA
"CIM_DirectoryContainsFile" and TargetInstance.GroupComponent=
"Win32_Directory.Name=\"c:\\\\ReceiveQueue\"" AND TargetInstance.Extension=
"txt"

however, that did not work. I have tried putting the txt in single quotes
inside the double quotes and using single quotes alone but nothing seems to
work.

What's the secret. Thanks in advance.

urkec

unread,
Nov 13, 2009, 11:30:06 AM11/13/09
to
"ewm" wrote:


If you look at the Cim_DirectoryContainsFile class you will see that it only
has two properties:

GroupComponent, representing the path to a Win32_Directory instance
PartComponent, representing the path to a CIM_DataFile instance

This is why your query doesn't work - there is no Extension property for
Cim_DirectoryContainsFile. This doesn't work either:

TargetInstance.PartComponent.Extension

because PartComponent (just as GroupComponent) contains just a path (as a
string). Here is an alternative query:

Select * From __InstanceCreationEvent Within 10 Where TargetInstance Isa
Cim_DataFile And TargetInstance.Drive = "C:" And TargetInstance.Path =
"\\ReceiveQueue\\" And TargetInstance.Extension = "txt"

Instead of Cim_DirectoryContainsFile, this query subscribes to Cim_dataFile
creation events, which allows you to rafine results using all Cim_dataFile
properties, including Extesion.


--
urkec

My blog:
http://theadminblog.blogspot.com/

My CodeProject articles:
http://www.codeproject.com/script/Articles/MemberArticles.aspx?amid=4210975

0 new messages