使用SSIS根据当前访问的文件夹递归导航生成动态xml文件的目录

发布于 2024-12-11 13:37:24 字数 303 浏览 0 评论 0原文

我需要使用 SSIS(SQL Server 集成服务)访问一个文件夹及其所有子文件夹。目前,通过在读取文件夹路径后将其设置为变量,我可以循环遍历当前文件夹的所有 .txt 文件并填充预先生成的(带有头信息)xml 文件。

我现在需要的是能够为每个访问的文件夹创建一个新的 xml 文件(开始内容始终相同)。一旦我能够创建它,首先一旦访问新文件夹,我就可以简单地应用迄今为止开发的逻辑。

然而,我现在被阻止了,因为在我读取文件(及其完整路径)的循环中,我无法找到一种方法来表达“如果访问的文件夹是新的,则创建 xml 文件”。

I need to visit a folder and all of its children with SSIS (SQL Server Integration Services). At the moment by setting the folder path into a variable after reading it, I able to loop through all the .txt files of the current folder and fill a pre-generated (with head info) xml file.

What I would need now is to be able to create one per each accessed folder, a new xml file (the beginning content will be always the same). Once I would be able to create it, as first action once a new folder is accessed, I can then simply apply the logic I developed so far.

However I am blocked at the moment, since within the loop where i read the files (with their full path) I cannot find a way to express "create the xml file if the accessed folder is new".

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

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

发布评论

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

评论(1

木有鱼丸 2024-12-18 13:37:24

假设我理解这个问题,您需要遍历整个目录结构,并且对于您找到的每个文件夹,您需要创建一个基本 XML 文件。然后,对于在该文件夹中找到的每个文本文件,您将对 XML 文件执行一些操作。诀窍是如何只创建一次 XML 文件。

在此处输入图像描述

我会设想这样的过程。

一个脚本任务,利用 System.IO.GetDirectories 来填充一个包含文件夹结构的变量(directoryXML>,类似于

<Dir>
    <D>C:\ssisdata</D>
    <D>C:\ssisdata\a</D>
    <D>C:\ssidata\a\b</D>
</Dir>

使用 Foreach Nodelist Enumerator 分解该 XML 您将执行

在 currentDirectory 中创建 XML 文件的一次性任务,

进一步使用 currentDirectory 变量作为 Foreach 文件枚举器上的表达式。 (分配给 FileSpec 为 *.txt 的目录),然后您可以对满足该规范的所有文件执行任务。不要选中遍历子文件夹选项,因为这不会给出所需的结果。

这是一种相当高级的方法。我假设您对 SSIS 有一定的了解,但该方法应该是合理的,如果您有任何特定的症结,请告诉我。

Assuming I understand the problem, you need to walk the entirety of a directory structure and for each folder you find, you need to create a base XML file. Then for each text file you find in that folder, you will perform some operation on the XML file. The trick being how do you only create the XML file once.

enter image description here

I would envision a process like this.

A script task that makes use of the System.IO.GetDirectories to populate a variable (directoryXML> that contains the folder structure, something like

<Dir>
    <D>C:\ssisdata</D>
    <D>C:\ssisdata\a</D>
    <D>C:\ssidata\a\b</D>
</Dir>

Use a Foreach Nodelist Enumerator to shred that XML out into a variable (currentDirecotry).

You'd perform your one-time task of creating the XML file in currentDirectory.

Further using the currentDirectory variable as an expression on the Foreach File Enumerator (assign to Directory with a FileSpec of *.txt) you can then perform your task on all the files meeting that specification. Do not check the traverse subfolder option as that will not give the desired results.

This is a fairly high level approach to the problem as I'm assuming you have some familiarity with SSIS but the approach should be sound. Let me know if you have any particular sticking points.

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