1

I've followed the suggestions on this and other sites to check if a file exists using a Script Task. The code works perfectly (steps only run if the file exists) so long as I don't want to do some different processing if the file does not exist. When I try to branch to different processing when the file does not exist that branch never executes and the package completes successfully without running the steps in the "file does not exist" branch. Here's what the package is doing.

  1. See if a header file exists. If yes, go to step 2. If no, go to step 4.
  2. Process the header file
  3. Delete the header file
  4. See if a detail file exists. If yes, go to step 5. If no, stop processing
  5. Process the detail file
  6. Delete the detail file

Package variables:

blnFileExists: Boolean, defaults to False

strListIndexFileFullPath: string, expression based upon other string variables that set file name and file path

Script Task

Properties: FailPackageOnFailure: False, FailParentOnFailure: False

Imports System.IO
Public Sub Main()
    Dts.Variables("blnFileExists").Value = File.Exists(Dts.Variables("strListIndexFileFullPath").Value)
    Dts.TaskResult = ScriptResults.Success
End Sub

Properties of "file exists" constraint > Evaluation operation: Expression and Constraint, Value: Success, Expression: @blnFileExists==True, Using Logical AND

Properties of "file does not exist" constraint > Evaluation operation: Expression and Constraint, Value: Success, Expression: @blnFileExists==False, Using Logical AND

user1078196
  • 11
  • 1
  • 3

1 Answers1

3

In the Precedence Constraint Editor, you need to change Logical AND to Logical OR.

In your scenario, you want the package to take either the path when blnFileExists value is true or the path when blnFileExists value is false. (Notice the OR in the sentence) If you set the constraint to Logical AND, then the package will expect both the expressions to succeed. It is not possible in this scenario because the variable blnFileExists can have only true or false and not both.

Having said that, you actually don't need to use Script Task to check if a file exists or not. You can make use of File System Task to do the same.

Please have a look at my answer in the below link to see how you can check whether a file exist or not using File System Task. When you use File System Task, you won't need to write any C# code or make use of expressions in precedence constraints.

Branching after a file system task in SSIS without failing the package

Hope that helps.

Community
  • 1
  • 1
  • Siva - Thank you VERY much. The Logical OR was the answer. Obvious now that you've pointed it out. Thanks also for referencing your other solution - I had actually found that and tried to use, but I was still using Logical AND which explains why I couldn't get your solution to work. – user1078196 Dec 05 '11 at 19:24