-1

我对 ETL 的世界非常陌生,尽管自从我 3 个月前开始学习 ETL 以来,我已经使用 SSIS 完成了几次 ETL。对于有经验的人,我有一个很好的问题。

. 我想用文件夹中的文件信息( Filename、FileSize 和 ReceivedDate )在我创建的数据库中填充一个表。使用 SSIS 包。一个示例是在 sql 数据库中加载以下路径中的文件信息。

C:\Users\Documents\newfiles\purchaseorder。C:\用户\文档\新文件\发票。

另请注意,我有多种类型的文件。csv、edi、tcf 等

任何人都可以提供解决此问题的分步指南吗?

谢谢。

4

2 回答 2

2

The simplest way to get that sort of information is to use the .NET Framework's System.IO.FileInfo class in a Script Task:

   public void Main()
    {
        var receivedFile = (string)Dts.Variables["User::ReceivedFile"].Value;
        var fileInfo = new System.IO.FileInfo(receivedFile);
        Dts.Variables["User::FileName"].Value = fileInfo.FullName;
        Dts.Variables["User::FileSize"].Value = fileInfo.Length;
        Dts.Variables["User::ReceivedDate"].Value = fileInfo.CreationTime;
        // or whatever other information you may need

        Dts.TaskResult = (int)ScriptResults.Success;
    }

The code above assumes that you've set the User::ReceivedFile variable to the full path of whatever file you're dealing with; this is typically (but not always) done through a File System Task. Obviously, when configuring the Script Task, you'll need to specify ReadWrite access for the variables you'll be writing to.

Once you have that information in variables, of course, you can use it in whatever manner is needed.

For further information on the FileInfo class, see MSDN here.

于 2013-03-18T20:40:37.030 回答
1

这是我用来提取信息的一段代码......

     HHInfo = New FileInfo(HHFile(i).ToString())

    HHFileDate = HHInfo.CreationTime

  HHDate = HHFileDate.ToString("dd/MM/yyyy")
                    writer.Write("HHInfo.CreationTime  : " & HHInfo.CreationTime.ToString & vbNewLine & vbNewLine)
                    writer.Write("HHInfo.LastAccessTime  : " & HHInfo.LastAccessTime.ToString & vbNewLine & vbNewLine)
                    writer.Write("HHInfo.LastWriteTime  : " & HHInfo.LastWriteTime.ToString & vbNewLine & vbNewLine)

                    HHElapsedTime = New DateTime(((HHInfo.LastWriteTime - HHInfo.CreationTime).Ticks))

                    EndTimelist.Add(HHInfo.LastWriteTime)

                    writer.Write("HHElapsedTime  : " & HHElapsedTime.ToString("HH:mm:ss") & vbNewLine & vbNewLine)

                    swriter.WriteLine("HH Start Time  : " & HHInfo.CreationTime.ToString & vbNewLine)
                    swriter.WriteLine("HH End Time  : " & HHInfo.LastWriteTime.ToString & vbNewLine)
于 2013-03-19T11:21:50.650 回答