问题描述
我得到了一个贯穿文件夹的软件包,它是子文件夹,用于获取客户端数据.协议已更改,现在客户端每次将其数据发布到不同的文件夹名称中.我想知道是否可以在主文件夹上执行foreach循环并排除archive
这样的特定文件夹.
I got a package that runs through a folder and it's sub folders to get client data. The agreement has changed and now the client will post his data in different folder name every time. I was wondering if I can do a foreach loop on the main folder and exclude specific folders like archive
.
我没有编写脚本的知识,所以我想知道SSIS是否可以在没有脚本的情况下做到这一点.
I don't have knowledge in writing scripts so I was wondering if SSIS can do that without the script.
推荐答案
使用执行脚本任务
使用Execute Script Task
获取-过滤后的文件的列表,然后进入循环并循环,然后使用ForEach循环容器(Ado枚举器)
Using Execute Script Task
Get List of - filtered - files using an Execute Script Task
before entering Loop and loop over then using ForEach Loop container (Ado enumerator)
- 您必须具有类型为
System.Object
(范围:包) 的SSIS变量(例如: - 在每个Loop容器的前面添加
Execute Script Task
,并将User::FilesList
作为 ReadWrite变量 添加 -
在脚本中编写以下代码:
User::FilesList
)- You have to a a SSIS variable (ex:
User::FilesList
) with typeSystem.Object
(Scope: Package) - Add an
Execute Script Task
before the for each Loop container and addUser::FilesList
as a ReadWrite Variable In the Script Write The following Code:
Imports System.Linq
Imports System.IO
Imports System.Collections.Generic
Public Sub Main()
Dim Directory as String = "C\Temp"
Dim strSubDirectory as String = Directory & "\New Folder"
Dim lstFiles As New List(Of String)
lstFiles.AddRange(Directory.GetFiles(Directory, "*.*", SearchOption.TopDirectoryOnly).Where(Function(x) Not x.Contains(strSubDirectory)).ToList)
Dts.Variables.Item("FilesList").Value = lstFiles
Dts.TaskResult = ScriptResults.Success
End Sub
在对于每个循环容器"中,将枚举类型选择为From variable Enumerator
,然后选择FilesList
变量作为源
In the For each Loop Container Choose the Enumertaion Type as From variable Enumerator
and choose FilesList
variable as a source
屏幕截图
有关更多详细信息,请参阅以下链接中的我的回答(这是类似的情况)
这篇关于排除特定的子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!