SSIS读取文件修改日期

时间:2015-07-22 07:46:56

标签: sql-server ssis fileinfo

我们有一个SSIS流程,可以从各种来源导入不同格式的各种文件。 这些文件中的每一个都在整个月的不同时间交付。

用户希望能够看到每个文件的修改日期,以检查他们是否定期更新。

目标是在流程结束时生成一个表格,如下所示:

Desired Table

所以我想弄清楚如何获取我读过的每个文件的修改日期。有没有办法在SSIS中执行此操作?

提前致谢

1 个答案:

答案 0 :(得分:10)

您可以向管道添加脚本组件,该管道从输入变量读取文件名,并将文件修改日期写入输出变量:

    /// <summary>
    /// This method is called when this script task executes in the control flow.
    /// Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.
    /// To open Help, press F1.
    /// </summary>
    public void Main()
    {
        System.IO.FileInfo theFile = 
              new System.IO.FileInfo(Dts.Variables["User::FilePath"].Value.ToString());

        if (theFile.Exists)
        {
            Dts.Variables["User::LastFileDate"].Value = theFile.LastWriteTime;
        }
        Dts.TaskResult = (int)ScriptResults.Success;
    }
相关问题