Reputation: 2578
I have an SSIS package (SQL 2016) that loads files into a database.
At the beginning of the package I have a Foreach Loop container (Foreach File Enumerator). This loop checks to see if there are any files in an error folder. The desired condition is that there are no files in the error folder.
The ETL works well. However, when there are no files in the error folder, the Foreach Loop container generates a warning:
Foreach File - Check Error Folder:Warning: The For Each File enumerator is empty. The For Each File enumerator did not find any files that matched the file pattern, or the specified directory was empty.
Since this is the desired situation (that there are no files) and since my control flow handles the situation either way, is there a way to suppress this warning?
The reason for wanting to suppress the warning is because the warning count on the package is always 1. Sometimes, however, SSIS warnings are important (such as when fields get out sync). I'd prefer not to have packages that always have warnings since they could mask other, genuine, issues.
It sounds like a small thing, so I thought for sure there'd be a way, but I haven't found it. I tried setting an OnWarning event handler on the Foreach loop and setting Propagate to False. But the warning still gets counted as a warning when the package runs.
Upvotes: 2
Views: 1972
Reputation: 1280
I think the best way to solve this small issue is to write a very small script task. Just pass input variable with the path to a folder into the script task, check files count and return output variable back and then use the precedence constraint with an expression
Dts.Variables["User::GoFurther"].Value = Directory.GetFiles(Dts.Variables["User::Path"].Value.ToString()).Any();
Upvotes: 3