ryan
ryan

Reputation: 91

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

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?

Upvotes: 1

Views: 10516

Answers (1)

Rahul Sharma
Rahul Sharma

Reputation: 453

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

Upvotes: 4

Related Questions