All files need to be available before running

  • I am very new to SSIS, so please bear with me … I’ve created an SSIS package that imports five .txt files from a shared network folder into their respective tables. However, I only want this package to run if all five files are available. Is there a way to create this with a task – I don’t see one that looks obvious to me. Any help you can provide would be greatly appreciated!!

  • There could be many ways you could do this. Here is one.

    Step1: First create a variable called DisableStep of datatype boolean

    Step 2: put all your package main tasks into a sequence container.

    Step 3 : before this sequence container add a script task. And in the ReadWriteVariables add DisableStep. Now in the script task add the following code. Change the path to your file path.

    If File.Exists("C:\File1.txt") And File.Exists("C:\File2.txt") And File.Exists("C:\File3.txt") And File.Exists("C:\File4.txt") And File.Exists("C:\File5.txt") Then

    Dts.Variables.Item("DisableStep").Value = False

    Else

    Dts.Variables.Item("DisableStep").Value = True

    End If

    final step is to use this variable in your precedence constraint using expression.

    HTH

    ~Mukti

  • Thanks for your reply!

    But I'm running into problems ...

    I’ve created my variable, added the Script Task to my Control Flow, and added my variable under ReadWrite. As for the code – I’m assuming I need to click on the Edit Script button – but I get lots of blue squiggly lines under the code. I have tried changing the ScriptLanguage from both C# and VB and get errors both ways. Am I even in the right place to enter the code? Thanks so much for your assistance!!

  • Forgot to mention that you would need to import System.IO to use File class.

    Imports System.IO

    ~Mukti

  • I have a little thought on this. I know "Mukti" way is fine, It works. But, instead of hardcoding all the file name in the script task, I would rather use some other logic to check the files on teh folder and assgin a value to a variable everytime it finds a file and then when its five run the rest of the step.

    Now, it depends what other things u have on the folders, like other files , or .........

    thanks

  • I have a designated folder that contains my five files, plus one other file that shows up occasionally to prompt me to change rates – other than that there is nothing else in the folder. The folder resides on a shared drive on our network. Hope that helps.

Viewing 6 posts - 1 through 5 (of 5 total)

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