我在SSIS包写入时有点新,我在SSIS包中嵌套循环,一个循环将所有文件夹放到一个位置,内循环循环遍历每个文件夹中的所有文件。
在文件夹级循环中,我的第一个任务是脚本任务,其中我将所有文件路径提取到一个对象变量中,包级别作为字符串数组,如下所示。
string targetDirectory = Convert.ToString(Dts.Variables["SourceFolderLocation"].Value);
string[] fileEntries = Directory.GetFiles(targetDirectory, "*.pdf");
Dts.Variables["FileList"].Value = fileEntries;
Dts.Variables [“FileList”]。值是包含程度范围的对象变量。
现在我的要求是在文件夹级循环的脚本任务中,首先重置该对象变量,然后将新文件列表设置为该对象变量,就像我得到访问文件夹的任何异常一样,它不应该处理以前文件夹的文件。
我的问题是如何在脚本任务c#代码中重置对象变量?所以它不会再次处理上一个文件夹的文件,也不会让枚举器不包含空值错误。
非常感谢任何帮助。
答案 0 :(得分:1)
如果我理解正确,您应该可以在致电string[]
之前将其设置为新的GetFiles
以“重置”它。
string[] fileEntries = new string[] {};
try {
string targetDirectory = Convert.ToString(Dts.Variables["SourceFolderLocation"].Value);
fileEntries = Directory.GetFiles(targetDirectory, "*.pdf");
Dts.Variables["FileList"].Value = fileEntries;
}
catch (Exeception e) {
// handle exception
}