Looping through Files in SSIS 2005

  • Hi All,

    I'm totally new to SSIS 2005 and i have the following requirements.

    Scenario:

    In my server i will be having folders which will be having 4 .csv files to be mapped to tables in the sqlserver.This folders will be created on daily basis and folder names will be in date format like 11062010,11062010 etc.

    Tasks

    ------

    1)Validate 4 files whether it exists inside respective date folders.

    2)If exists have to loop through the four files and need to extract the date from the file and pass that date to a sql task in the package

    Can any one please help me on this it's an urgent requirement.

  • To validate if the 4 files are present in the folder, you can use a Script Task. The code for this isn't really complex (if needed I can provide you with the code, but it's always better to try it out yourself :-)).

    If the 4 files are found, you can loop over them with a for each loop container. Use a wildcard like *.csv to pick up the files. Connect the script task and the for each loop container with a precedence constraint so that the loop only starts if all the files are present.

    In the For Each Loop, you can set the filename of the current file to a variable. Use this to substract the date that you need. From your post I couldn't make up if you need the files contents. If so, you need a dataflow task. If all the files are similar in structure, you need only one dataflow task with a flat file source. Configure the flat file source with expressions. If the files are different, you need one dataflow per file.

    I hope this helps. If you have any questions, just ask them.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • Hi,

    Thanks for the reply.I need to loop through folders and the corresponding files inside a folder.

    Suppose i'm having a root folder A1 and it has sub folders A2 & A3 and A2 has files 1.csv,2.csv.I need to loop through files inside A2.Similarily for A3 folder.Can u plz help me on this.

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

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