How to add multiple file extensions to the Files: input field in the Foreach loop container SSIS

心不动则不痛 提交于 2019-12-31 03:08:13

问题


How could I add multiple file extensions to the Files: input field in the Foreach loop container in SSIS 2008.

I have currently entered as *.zip OR .csv see image... but it doesn not work only works if I have one value like *.zip


回答1:


I don't think you can specify two file type extensions in a For each Loop container , you should use *.* and you can filter for a specific extensions by using the following steps:

  1. add a Variable of type boolean (ex: User::Flag)
  2. add a script task inside the container and mark Filename variable as Readonly , Flag variable as ReadWrite

  1. Inside the script write the following script

    Public Sub Main()
    
        Dim strFile As String = Dts.Variables.Item("Filename").Value.ToString
    
        Select Case IO.Path.GetExtension(strFile).ToLower
            Case ".csv", ".zip"
                Dts.Variables.Item("Flag").Value = True
    
    
            Case Else
                Dts.Variables.Item("Flag").Value = False
        End Select
    
    
        Dts.TaskResult = ScriptResults.Success
    End Sub
    
  2. Add an expression to the Script task output connector like shown below

Or you can achieve it by using a Third-party components like Foreach File Enumerator with regex




回答2:


Step 1) Create a variable which store the file name with the extension.
Step 2) Under the foreach loop container Map the variable which we created in step 1.
Step 3) create a execute sql task inside the foreach loop container, add connection and under sql statement enter the code insert into tablename(filename) values (?).
Step 4) Under parameter mapping select the variable which we created under variable name, changed the data type to nvarchar and changed parameter to 0.
Step 5) With the help of string function then you can create an expression with the help of string function like right



来源:https://stackoverflow.com/questions/43195171/how-to-add-multiple-file-extensions-to-the-files-input-field-in-the-foreach-loo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!