排除特定的子文件夹 [英] Exclude specific Sub Folders

查看:103
本文介绍了排除特定的子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了一个贯穿文件夹的软件包,它是子文件夹,用于获取客户端数据.协议已更改,现在客户端每次将其数据发布到不同的文件夹名称中.我想知道是否可以在主文件夹上执行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)

  1. 您必须具有类型为System.Object (范围:包)
  2. 的SSIS变量(例如:User::FilesList)
  3. 在每个Loop容器的前面添加Execute Script Task,并将User::FilesList作为 ReadWrite变量
  4. 添加
  5. 在脚本中编写以下代码:

  1. You have to a a SSIS variable (ex: User::FilesList) with type System.Object (Scope: Package)
  2. Add an Execute Script Task before the for each Loop container and add User::FilesList as a ReadWrite Variable
  3. 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

    屏幕截图

    有关更多详细信息,请参阅以下链接中的我的回答(这是类似的情况) 查看全文

  • 登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆