Using a For Loop and Script Task objects to monitor the file system.
In this example, I’ll illustrate how to use a For Loop container to wrap a Scrip Task object which iteratively monitors the file system for the presence of a file and once found, uses another Script Task object to notify the user.
I’ll begin my adding a variable which will be used to communicate a condition between the objects of this package – whether or not the file has been found.
Now I will add a For Loop Container which will contain a task that will iterate through a folder I determine, looking for the file I specify.
Notice that I’ve renamed the container so it’s purpose is intuitive to another developer.
Inside the For Loop I will drag a Script Task and rename it to illustrate its purpose.
By double-clicking the task, I’m able to set the ReadWriteVariable to use my new custom variable.
Also, I am able to “Edit the Script” to add my own custom C# which check my folder for the presence of a file and when it’s found, sets my variable to ‘1’.
Next, I’ll add another Script Task which will notify me when my file has been detected once I “Edit the Script” for it.
Once I connect the Success constraint between the For Loop container to the new Script Task, I’m ready to execute.
Upon executing my package, the For Loop task remains yellow until I add the file it’s looking for in the folder.
Once the file has been detected, I receive a prompt.
Now my package has completed its task.