如何在 SSIS foreach 循环容器中使用带有文件名字母的通配符

How do I use a wild card with alphabets of file name in SSIS foreach loop container

SSIS 中的 for each 循环编辑器带有一个选项,可以选择循环枚举器作为 Foreach 文件枚举器,我试图在该选项下使用通配符来避免额外的脚本任务,但文件未被读取。我有以扩展名 .csv 结尾的文件列表,所以如果我执行 *.csv 它将读取所有文件,但我想要仅以“_names.csv”结尾的文件,但是该包无法读取任何文件如果我这样做的话。我附上了我的 Foreach 循环编辑器设置的屏幕截图。任何想法我做错了什么?我使用 ls -file *_names.csv 在 PowerShell 中测试了这个通配符,我得到了过滤后的文件列表。

它对我有用,所以你的情况可能有其他问题。

设置

在磁盘上,我的输入文件夹中有 3 个文件,只有一个符合预期条件

  • C:\ssisdata\so\input\foo_names.csv
  • C:\ssisdata\so\input\norms.csv
  • C:\ssisdata\so\input\no_names.csvv

我的 SSIS 包有 3 个变量,都是字符串类型。

  • CurrentFileName - 这是在我的 ForEach 循环的每次迭代中填充的
  • FileNameFilter - 这是 *_names.csv
  • FolderName - 这指向 C:\ssisdata\so\input

脚本任务只是将变量值打印到 output/results 选项卡的一小段代码。命名空间将根据单击创建脚本任务的随机性而有所不同

using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;

namespace ST_6da5625c3b1a4e13988a4a2c68531e4d
{
    [Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
    public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
    {
        public void Main()
        {
            bool fireAgain = false;
            foreach (var item in Dts.Variables)
            {
                Dts.Events.FireInformation(0, "SCR Echo Back", string.Format("{0}:{1} -> {2}", item.Namespace, item.Name, item.Value), "", 0, ref fireAgain);
            }

            Dts.TaskResult = (int)ScriptResults.Success;
        }
        enum ScriptResults
        {
            Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
            Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
        };
    }
}

测试用例

我使用的第一个案例是一个简单的 *.csv 以确保是的,我看到了文件。这消除了诸如权限或损坏的路径问题之类的问题。如果这是 path/permissions 问题,您会看到以下警告

Warning: 0x8001C004 at FELC name csv: The For Each File enumerator is empty. The For Each File enumerator did not find any files that matched the file pattern, or the specified directory was empty.

有关 *.csv 迭代的注意事项,它拾取了 no_names.csvv 为什么?因为它是为 8.3 名称设计的。 我太懒了,没有引用

然后我使用 N*.csv 作为我的下一个迭代。它接收到 norms.csv 而没有接收到预期的 _names.csvv。

最后,我使用原始的 *_names.csv 作为我的输入过滤器,它正确地提取了 foo_names.csv

输出

SSIS package "C:\Users\bfellows\source\repos\SO_Trash\SO_Trash\so_69215306.dtsx" starting.
Information: 0x0 at SCR Echo Back, SCR Echo Back: User:FileNameFilter -> *.csv
Information: 0x0 at SCR Echo Back, SCR Echo Back: User:FolderName -> C:\ssisdata\so\input
Information: 0x0 at SCR Echo Back, SCR Echo Back: User:CurrentFileName -> C:\ssisdata\so\input\foo_names.csv
Information: 0x0 at SCR Echo Back, SCR Echo Back: User:CurrentFileName -> C:\ssisdata\so\input\norms.csv
Information: 0x0 at SCR Echo Back, SCR Echo Back: User:CurrentFileName -> C:\ssisdata\so\input\no_names.csvv
SSIS package "C:\Users\bfellows\source\repos\SO_Trash\SO_Trash\so_69215306.dtsx" finished: Success.

SSIS package "C:\Users\bfellows\source\repos\SO_Trash\SO_Trash\so_69215306.dtsx" starting.
Information: 0x0 at SCR Echo Back, SCR Echo Back: User:FileNameFilter -> N*.csv
Information: 0x0 at SCR Echo Back, SCR Echo Back: User:FolderName -> C:\ssisdata\so\input
Information: 0x0 at SCR Echo Back, SCR Echo Back: User:CurrentFileName -> C:\ssisdata\so\input\norms.csv
Information: 0x0 at SCR Echo Back, SCR Echo Back: User:CurrentFileName -> C:\ssisdata\so\input\no_names.csvv
SSIS package "C:\Users\bfellows\source\repos\SO_Trash\SO_Trash\so_69215306.dtsx" finished: Success.
The program '[49988] DtsDebugHost.exe: DTS' has exited with code 0 (0x0).

SSIS package "C:\Users\bfellows\source\repos\SO_Trash\SO_Trash\so_69215306.dtsx" starting.
Information: 0x0 at SCR Echo Back, SCR Echo Back: User:FileNameFilter -> *_names.csv
Information: 0x0 at SCR Echo Back, SCR Echo Back: User:FolderName -> C:\ssisdata\so\input
Information: 0x0 at SCR Echo Back, SCR Echo Back: User:CurrentFileName -> C:\ssisdata\so\input\foo_names.csv
SSIS package "C:\Users\bfellows\source\repos\SO_Trash\SO_Trash\so_69215306.dtsx" finished: Success.