can ssis pick up the file with the latest date creation?

馋奶兔 提交于 2020-12-13 18:51:35

问题


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.

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.

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


回答1:


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


来源:https://stackoverflow.com/questions/27161004/can-ssis-pick-up-the-file-with-the-latest-date-creation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!