wql query to check for creation of multiple files in a directory

  • Hello all,

    I need help modifying this query so that it watches for the creation of 2 (or more) files:

    Dim query1 As New WqlEventQuery( _

    "SELECT * FROM __InstanceCreationEvent WITHIN 5 WHERE " & _

    "TargetInstance ISA 'CIM_DataFile'" & _

    " AND TargetInstance.Name = '' & _

    "AND TargetInstance.Name = ''C:\\Users\\plain\\Documents\\test\\test.csv' ")

  • I am not sure how you would do this in one WMI query. I would setup two watchers in sequence...when the first watcher finds a file it will pass control to the second watcher. When the second watcher finds its file it will pass control to your next task allowing your package to do work. I think that will give you what you want.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • Thanks for your response. I have already tried that appraoch but because the files are created at the same time the 2nd watcher does not recognise the 2nd file because it was created at the same time as the 1st file

  • AIRWALKER-375999 (4/19/2012)


    Hello all,

    I need help modifying this query so that it watches for the creation of 2 (or more) files:

    Dim query1 As New WqlEventQuery( _

    "SELECT * FROM __InstanceCreationEvent WITHIN 5 WHERE " & _

    "TargetInstance ISA 'CIM_DataFile'" & _

    " AND TargetInstance.Name = '' & _

    "AND TargetInstance.Name = ''C:\\Users\\plain\\Documents\\test\\test.csv' ")

    How about this...

    IF(File.Exists(@var1) && File.Exists(@var2))

    {

    Go ahead

    }

    ELSE

    {

    Wait for 5 seconds and poll the directory again after 5 seconds

    }

    Raunak J

  • AIRWALKER-375999 (4/20/2012)


    Thanks for your response. I have already tried that appraoch but because the files are created at the same time the 2nd watcher does not recognise the 2nd file because it was created at the same time as the 1st file

    Fair enough, I should have considered that. What you can try then is two separate watchers in a Sequence Container where the watchers are not connected. This way the watchers will both run in parallel, and the Sequence Container will handle your control flow.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • opc.three (4/20/2012)


    AIRWALKER-375999 (4/20/2012)


    Thanks for your response. I have already tried that appraoch but because the files are created at the same time the 2nd watcher does not recognise the 2nd file because it was created at the same time as the 1st file

    Fair enough, I should have considered that. What you can try then is two separate watchers in a Sequence Container where the watchers are not connected. This way the watchers will both run in parallel, and the Sequence Container will handle your control flow.

    Thanks again, I'll try that, but the work around I came up with was to use the event watcher task trigger a script task that then checks for the existence of the extra files.

    Perhaps you can help me with another issue. I have wmi event watcher steps. If the 1st event watcher task succeeds it triggers some other tasks that do some file processing and integration. If the 1st event watcher task fails it moves onto the 2nd event watcher task.

    What I want to is have the process flow like this:

    If 1st event watcher step succeeds then move onto the file processing tasks. When they have completed the process flow should move onto the 2nd event watcher task. In addition, if the 1st file watcher tasks fails or timesout, it should move onto the 2nd event watcher task. I have tried using precedence constraints and precedence constraints + variables to acheive this, but it seems like I cant have 2 constraints pointing to the same task..is there a way around this?

    Thanks

  • AIRWALKER-375999 (4/20/2012)


    ...but it seems like I cant have 2 constraints pointing to the same task..is there a way around this?

    Sure you can...I do it all the time. When you have multiple constraints pointing to a task you can also play around with the Logical behavior to say "this task OR that task" can make the next task proceed....or you can say "this task AND that task" can make the next task proceed.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • Fantastic, many thanks

  • AIRWALKER-375999 (4/20/2012)


    opc.three (4/20/2012)


    AIRWALKER-375999 (4/20/2012)


    Thanks for your response. I have already tried that appraoch but because the files are created at the same time the 2nd watcher does not recognise the 2nd file because it was created at the same time as the 1st file

    Fair enough, I should have considered that. What you can try then is two separate watchers in a Sequence Container where the watchers are not connected. This way the watchers will both run in parallel, and the Sequence Container will handle your control flow.

    Thanks again, I'll try that, but the work around I came up with was to use the event watcher task trigger a script task that then checks for the existence of the extra files.

    I know this was from a couple weeks ago and that your project work may be complete, but I just learned about the NumberOfEvents property on the WMI Event Watcher Task and thought you may be interested. It is defaulted to 1 but if set higher it will wait for that number of events to occur before the task is satisfied and will raise the event to your SSIS package. This property is useful for watching a folder for multiple files to arrive, provided your WQL is properly created.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply