与Tim的帖子类似的逻辑(我没有安装SSIS,但是我确实有BimlStudio,所以请接受SSIS对象的不同图标)。
3个变量
-
CurrentFilename
字符串-该字符串将包含当前文件名,该文件名可能包含也可能不包含排除值
-
ExclusionList
字符串-您要排除的文件夹的分隔字符串
-
IncludeCurrent
布尔值-False,我们将按循环覆盖
在Foreach文件循环中,我将使用脚本任务,因为它将成为拆分ExclusionList
以及执行文件系统测试的最有效方法。运行脚本任务的结果是,我们将@[User::IncludeCurrent]
的值设置为true或false。
脚本任务和数据流任务之间的先行约束逻辑将从参考帖子简化为@[User::IncludeCurrent]
。
如果满足条件,我们将执行DFT任务。否则,我们将其跳过。
测试是否包含
您将需要将CurrentFilename和ExclusionList作为只读变量传递到Script任务中。 IncludeCurrent将作为读/写变量传递。
// use the .net native split method to split on commas
var fileList = Dts.Variables["ExclusionList"].Value.Split(new Char[] {','});
// We could inline this for the next operation but you might have need for this elsewhere
string currentFilename = Dts.Variables["CurrentFilename"].Value.ToString();
// https://stackoverflow.com/questions/500925/check-if-a-string-contains-an-element-from-a-list-of-strings
bool isFound = fileList.Any(s=>currentFileName.Contains(s));
// Assign the results back to our SSIS scoped variable
Dts.Variables["IncludeCurrent"].Value = isFound;
关于拉杰·莫尔(Raj More)提议的说明
SPLIT_STRING假定使用SQL Server 2016+。作为顾问,我希望我可以指望可用的最新功能,但事实并非如此。
我相信每种循环方法的双重处理可能会遇到的挑战是,在第一次通过之后,内部记录集(查询的拆分列表)会被标记为已用尽,因此您需要将此方法修改为FELC所有文件- > OLE DB查询-> FELC过滤器
如果您要进行比纯字符串匹配更复杂的测试,则脚本方法将提供最大的灵活性。
,
我将连接到数据库,执行SPLIT_STRING,将结果放回一个对象,并在每个文件夹名称上使用for-each loop
。因此,您将有两个for-each循环,外部的是查找匹配项,以及查找子文件夹的内部匹配项。
此外,请记住在SSIS中的字符串比较中要考虑大小写敏感性。
,
感谢所有回答了我的问题。这是我降落的地方。我相信这可以改善。没有你们,我绝对不可能做到这一点!!!!谢谢!
创建项目变量
EFTFileSystem_FoldersToBeExcludedFromPolling定义为字符串。以逗号分隔。示例“已处理,错误”
EFTFileSystem_NewFileName-从SSIS中为每个循环容器单个值填充。示例“ c:\ effy \ bozo \ SideShowBob.txt”
EFTFileSystem_IsValidNewFile-如果文件位于有效文件夹中,脚本任务将返回完整路径。示例“ c:\ effy \ bozo \ KrustyGood.txt”
添加并配置“ Foreach循环容器”
在收集选项卡中
将“检索文件名”设置为完全限定
选择遍历子文件夹
在“变量映射”选项卡中
将变量设置为User :: EFTFileSystem_NewFileName
在“ Foreach循环容器”中
创建脚本任务
ReadOnlyVariables = User :: EFTFileSystem_FoldersToBeExcludedFromPolling,User :: EFTFileSystem_NewFileName
ReadWriteVariables = User :: EFTFileSystem_IsValidNewFile
编辑脚本任务
添加到名称空间:使用System.Linq;
public void Main()
{
// TODO: Add your code here
// use the .net native split method to split on commas
string Bob = Dts.Variables["EFTFileSystem_FoldersToBeExcludedFromPolling"].Value.ToString();
var fileList = Bob.Split(new Char[] { ',' });
// We could inline this for the next operation but you might have need for this elsewhere
string currentFilename = Dts.Variables["EFTFileSystem_NewFileName"].Value.ToString();
// https://stackoverflow.com/questions/500925/check-if-a-string-contains-an-element-from-a-list-of-strings
bool isFound = fileList.Any(s => currentFilename.Contains(s));
// Assign the results back to our SSIS scoped variable
Dts.Variables["EFTFileSystem_IsValidNewFile"].Value = !isFound;
Dts.TaskResult = (int)ScriptResults.Success;
}
本文链接:https://www.f2er.com/2445209.html