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.
- See if a header file exists. If yes, go to step 2. If no, go to step 4.
- Process the header file
- Delete the header file
- See if a detail file exists. If yes, go to step 5. If no, stop processing
- Process the detail file
- 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