@Raj More gave a good solution. Another way I used earlier is to create a Foreach contour Container that iterates over the file system to specify a file. If you know the name of the file you need, then you can set the name in a variable and set the specification to an equal variable on the expression tab for the Foreach loop container. You can also simply specify either a directory or a partial file name if you do not know the exact name, but know the naming convention or know that there will be no other files in the folder.
If you want to take a specific action based on whether there is a file, you can create a variable with a default value of 0 and create a script task in the Foreach loop container that increments this variable. You can also simply put the commands in the loop loop container that you want to execute if you want to execute it for each individual file to exist. If you want to take action based on the lack of a file, then you can limit the priority restriction after the Foreach contour Container so that it is limited by restrictions and expressions and does this by checking if there is a counter variable> 0.
The @Raj solution can also be used to increment a variable. Instead of using If Else to increase the error or result of success, you can do the following:
FROM#
if (System.IO.File.Exists("\\Server\Share\Folder\File.Ext")) { Dts.Variables["my_case_sensitive_variable_name"].Value = Dts.Variables["my_case_sensitive_variable_name"].Value + 1; }
Vb.net
If System.IO.File.Exists("\\Server\Share\Folder\File.Ext") Then Dts.Variables["my_case_sensitive_variable_name"].Value = Dts.Variables["my_case_sensitive_variable_name"].Value + 1 End If
The advantage of this approach is that the package may not need to crash if there is no file. You can also use the variable name if the file changes, which you can either define as a variable in the package, or simply created in a script task. The only downside to @Raj's approach is that you need to know the name of the file you want to check.
Another option is to perform a file system task to rename a file to an existing name or copy the file to an existing location. If the file does not exist, you can redirect the error to an action. I do not recommend this solution, but I remember how he used it several years ago in one copy, where it really made sense. But in this particular case, I actually copied it to a real location.
Good luck
source share