3

I've a folder and each day a few flat files get copied into it. The files have the same format and same structure. However, I want to read them into my database based on their creation order.

Example: the file that was created at 1 pm must get processed before the one that was created at 2:pm. I was wondering if there is any simple trick for doing this? Oddly, I have to use SSIS 2008! Thanks!

Hadi
  • 36,233
  • 13
  • 65
  • 124
TheEsnSiavashi
  • 1,245
  • 1
  • 14
  • 29
  • 1
    Have a look at this blog post [`Get file properties with SSIS `](http://microsoft-ssis.blogspot.co.uk/2011/03/get-file-properties-with-ssis.html) – M.Ali Jan 14 '17 at 15:50

1 Answers1

3

The Good Thing is that you are using SSIS 2008 because it is allow Linq

My illustrations are for SSIS 2015 but it works with 2008

  • Add a variable of type Object User::dtFiles
  • Add a script task to your project and add your created variable as a ReadWriteVariable

enter image description here

  • In Your Script task write the following code:

You have to Import System.Linq Library

    Public Sub Main()
    '
    ' Add your code here
    '


    Dim strDirectory As String = "C:\New Folder"
    Dim dtFiles As New List(Of String)

    dtFiles.AddRange(IO.Directory.GetFiles(strDirectory, "*.*", IO.SearchOption.TopDirectoryOnly
                                           ).OrderBy(Function(x) IO.File.GetCreationTime(x)).ToList)


    Dts.Variables.Item("dtFiles").Value = dtFiles

    Dts.TaskResult = ScriptResults.Success
End Sub
  • Add a for each Loop Container

enter image description here

  • Change The for each loop to ado enumerator and set the datasource to User::dtFiles

enter image description here

Hadi
  • 36,233
  • 13
  • 65
  • 124