Processing multiple files from different directories

  • I have 4 file directories, each with files to be processed into one Staging table. the files have same number of columns and data types, however the files has different name.

    I was thinking of a Loop or For Each Loop but I don't know how do I set it up to go to 4 different directories, get files there and load them into a table.

    Please help.

  • A For Each Loop would normally be used if you have multiple files in one directory or set of sub directories. This means that the Loop can iteratively go through each file in the directory. I'm doubt a For Each Loop would therefore work here.

    When you say each file has a different name, do you mean each time you load the file the name will be different, or that all 4 files have different names but they are known? Personally, I think you'll need 4 File Connections, 1 for each file. As the files all have the same format, you'll be able to then use a UNION transformation, to combine all the rows, and then insert them into your Staging table.

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

  • hoseam - Friday, October 6, 2017 2:48 AM

    I have 4 file directories, each with files to be processed into one Staging table. the files have same number of columns and data types, however the files has different name.

    I was thinking of a Loop or For Each Loop but I don't know how do I set it up to go to 4 different directories, get files there and load them into a table.

    Please help.

    If the files are not too large in size, you could try this simple solution:

    1) Copy the files to a central folder
    2) Process them using a standard Foreach loop
    3) Delete/move the files

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.

  • create one foreach loop for the folders based on a record set created by a script
    then within the foreach do another foreach for each file within that folder.

    see http://microsoft-ssis.blogspot.ie/2011/01/foreach-folder-enumerator.html for some ways of doing it.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply