SSI-获取列表文件名并将存储在变量对象中

发布于 2025-02-03 19:09:57 字数 251 浏览 1 评论 0原文

嗨,我将CSV文件带入一个位置,我正在使用一个具有搜索循环容器的软件包,让我放置foreach文件eNumeDor,然后检查名称和扩展名,然后我去了可变映射并放置了我的文件名变量。然后,我将一个fileNamelist变量作为对象数据类型,可以用哪种工具将我的fileNamelist(对象)与每个文件名一起填充?

路径

用户/abc.csv 用户/azd.csv

将文件名获取到单个变量 ABC.CSV,AZD.CSV,

...

Hi I have csv file into one location, I am using a package that has a forearch loop container, get I put foreach file enumeador, and checked name and extension, then I went to variable mapping and put my filename variable. Then I have a filenamelist variable as object datatype, what tool I can use to fill my filenamelist (object) with each filename?

path

users/abc.csv
users/azd.csv

get filenames into single variable
abc.csv, azd.csv, ...

Regards

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

二货你真萌 2025-02-10 19:09:57

那不是foreach文件枚举器的工作方式

然后,我将一个fileNamelist变量作为对象数据类型,我可以用哪种工具用每个文件名填充我的fileNamelist(对象)?

在foreach枚举器的“变量映射”选项卡中,您提供了一个可容纳枚举器的当前值的变量。

在您的示例中,您在用户文件夹中有两个文件:abc.csv和azd.csv

foreach(file)枚举器具有SMARTS询问操作系统哪些文件与给定的文件蒙版(*.csv)匹配的文件在源文件夹(用户)。该完整列表不可用,因为您需要按顺序执行每个项目的任务。

您可能需要一个类型字符串的SSIS变量,称为CurrentFileName,然后将其使用filenamelist

第一次迭代,当前filename的值将是用户/abc.csv然后,您将任务添加到容器中,例如数据流任务加载数据,然后将文件系统任务的后继产品归档到其他文件夹中。

通过下一个迭代,CurrentFileName的值变为AZD.CSV,所有相同的任务都将被应用,但具有新的值。

一个常见的失误是将CurrentFileName的值连接到适当的连接管理器中,以便源/目标文件在数据流中更改。

不,

如果您真的需要存储一个值列表,我真的想要一个列表,那么对象的数据类型是正确的。然后,您正在寻找的是编写自己的脚本任务(C#或VB.NET),该任务生成文件列表并将其分配给变量的值。假设您选择了用户:: fileNamelist作为读/写变量,则该代码大约

// TODO: replace users with actual path
string directoryName = @"users";

// TODO: is this a valid filter?
string fileExtension = "*.csv";

// Instantiate the directory object
System.IO.DirectoryInfo directoryInfo = new System.IO.DirectoryInfo(directoryName);

// Change the SearchOption to AllDirectories if you need to search subfolders
System.IO.FileInfo[] legacyArray = directoryInfo.GetFiles(fileExtension, System.IO.SearchOption.TopDirectoryOnly);

// Assuming all is well, assign back to the SSIS scoped variable
// This is case sensitive so be wary
// Ensure you assign to the Value property as shown
Dts.Variables["User::filenamelist"].Value = legacyArray;

完成了任务,SSIS变量fileNamelist填充了值 - 现在呢?除了确保其不是null之外,SSIS中的对象数据类型实际上无法做太多。但是,您可以将该变量用作枚举器的源,但是这次,您将其更改为...标题中具有变量的某些内容,也许是变量枚举器?

That's not how the Foreach File Enumerator works

Then I have a filenamelist variable as object datatype, what tool I can use to fill my filenamelist (object) with each filename?

In the Variable mapping tab of the Foreach Enumerator, you provide a variable that will hold the current value of the enumerator.

In your sample, you have two files in the users folder: abc.csv and azd.csv

The ForEach (File) Enumerator has the smarts to ask the operating system what files match the given file mask (*.csv) that are in the source folder (users). That full list is not available to you as the assumption is you need to perform a task on each item in sequence.

You likely want an SSIS Variable of type String called CurrentFileName which you would then use where you have filenamelist

The first iteration through, the value of CurrentFileName would be users/abc.csv and you would then add Tasks into the container e.g. a data flow task to load data and then a successor of File System Task to archive the file to a different folder.

The next iteration through, the value of CurrentFileName becomes azd.csv and all the same tasks would be applied but with a new value.

A common misstep is wiring up the value of CurrentFileName into the appropriate Connection Manager so that the source/target file changes in a Data Flow.

No, I really wanted a list

If you really need to store a list of values, then the datatype of object is correct. What you're then looking for is to write your own Script Task (C# or VB.NET) that generates the list of files and assigns it to the Variable's value. Assuming you have selected User::filenamelist as a read/write variable, that code is approximately

// TODO: replace users with actual path
string directoryName = @"users";

// TODO: is this a valid filter?
string fileExtension = "*.csv";

// Instantiate the directory object
System.IO.DirectoryInfo directoryInfo = new System.IO.DirectoryInfo(directoryName);

// Change the SearchOption to AllDirectories if you need to search subfolders
System.IO.FileInfo[] legacyArray = directoryInfo.GetFiles(fileExtension, System.IO.SearchOption.TopDirectoryOnly);

// Assuming all is well, assign back to the SSIS scoped variable
// This is case sensitive so be wary
// Ensure you assign to the Value property as shown
Dts.Variables["User::filenamelist"].Value = legacyArray;

The Task completes, the SSIS Variable filenamelist is populated with values - now what? You can't really do much with a object data type in SSIS beyond ensuring it's not null. However, you can use that variable as the source for a Foreach Enumerator but this time, instead of File, you'd change it to...something with Variable in the title, maybe Variable Enumerator?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文