ssis 可以获取最新创建日期的文件吗? [英] can ssis pick up the file with the latest date creation?

查看:49
本文介绍了ssis 可以获取最新创建日期的文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑使用ssis读取文件夹中的excel文件.

I am thinking of using ssis reading excel files in the folder.

该文件夹每天更新,通过放入新文件而不删除任何旧文件.

The folder is updated daily by putting new file in without deleting any old files.

我现在使用for each"容器来循环所有文件并将它们加载到统一表中.

I am now using a 'for each' container to loop all the files and loading them into a consolidated table.

但是,老板只想要最新的文件加载到表中,他不想要增量表.

However, the boss only wants the latest file to be loaded into the table and he does not want a incremental table.

ssis 是否可以使用 ssis 中的一些函数检查文件创建日期,并且只加载最新的一个?

Can ssis check the file creation date using some functions in ssis and only load the latest one?

推荐答案

ou can use this script:

      public void Main()
         {

      // TODO: Add your code here
             var directory= new DirectoryInfo(Dts.Variables["User::VarFolderPath"].Value.ToString());

            FileInfo[] files = directory.GetFiles();
            DateTime lastModified = DateTime.MinValue;

             foreach (FileInfo file in files)
            {
                if (file.LastWriteTime > lastModified)
                {
                    lastModified = file.LastWriteTime;
                    Dts.Variables["User::VarFileName"].Value = file.ToString();
                }
            }

             MessageBox.Show(Dts.Variables["User::VarFileName"].Value.ToString());


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

您也可以点击以下链接:

also you can cgeck this link below:

http://sqlage.blogspot.in/2013/12/ssis-how-to-get-most-recent-file-from.html

这篇关于ssis 可以获取最新创建日期的文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆