SSIS 在遍历子文件夹的 foreach 循环中检索当前文件夹
我使用 SSIS 读取输入中的 .txt 文件,并对其执行业务逻辑,将输出结果保存在与当前输入文件名称相同的文件中(文件名动态存储在变量中)。
当所有文件都存储在同一文件夹中时,访问它们没有问题,因为我对数据流中的平面文件连接字符串使用以下表达式: "path" + @[User::inputFileName] + " .txt"
现在我必须处理带有子文件夹的文件夹(我在 foreach 循环中设置遍历子文件夹),并且平面文件连接字符串存在一些问题,因为我无法使用如下通配符: my path \\子文件夹*" + @[User::inputFileName] + ".txt"
其中每个子文件夹都具有相同的名称,并且仅更改名称的最后一部分
如何将当前子文件夹名称保存在变量中,以便我可以。按以下方式使用它? "path\\"+ @[User::currentSubFolder] +"\\" + @[User::inputFileName] + ".txt"
I use SSIS to read .txt files in input and execute my business logic over them saving the output results in a file whose name is the same as the current inpout file (file name dynamically stored in a variable).
When all the files are stored in the same folder, I have no problem accessing them since I use the following expression for the flat file connection string in the data flow: "path" + @[User::inputFileName] + ".txt"
Now I have to process a folder with subfolders (I set traverse subfolders in the foreach loop) and I have some issues with the flat file connection string since I cannot use a wildcard like: my path\\subfolder*" + @[User::inputFileName] + ".txt"
where every subfolder has same name and changes only the last portion of the name.
How can I save the current subfolder name in a variable so that I can use it in the following way? "path\\"+ @[User::currentSubFolder] +"\\" + @[User::inputFileName] + ".txt"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我能够解决我的问题,因此我在这里写下我的解决方案,以防其他人遇到同样的情况。
我在 foreach 循环之前使用了脚本转换块。我可以从中检索当前的完整路径(随后在平面文件连接字符串中使用)和不带扩展名的输入文件名,以用作包含 SSIS 脚本结果的输出文件名。
为了保留兴趣值,我使用了 2 个变量:一个用于文件名,一个用于路径。
这里是脚本代码:
I was able to solve my issue, therefore I write here my solution in the case someone else would be in the same situation.
I used a script transformation block before my foreach loop. From it I can retrieve the current full path (used afterwards in the Flat File connection string) and the input file name without extension to be used as output file name containing the results of the SSIS scripts.
In order to keep the values of interests I used 2 variables: one for the file name and one for the path.
Here the script code: