HOW TO CREATE DYNAMIC FOLDER TO INSERT EXPORTED FILES INTO ??

  • Hi All,

    In my actual project, my boss asked me to export data from database to csv flat files.

    So, as I don't know .net code, I use SSIS File System task and ForEach Loop Container.

    I built a package which:

    1. Select data filtered by year, month and region

    2. Create differents folder to archive files exported like this:

    A- Year

    B - MONTH

    C-REGION

    D- csv Files.

    One difficulty that I have is to create folder only if it does not exist.

    Any help or suggestions would be appreciated.

    Thank U.

  • Hi,

    You can do this using scripting in vb or C# in SSIS script task. There is a beautiful post on this requirement.

    http://sqlserversolutions.blogspot.com/2009/01/creating-directory-using-ssis.html

    Thanks

    Varun

  • Hi Varun,

    Thank U for your answer.

    But one difficulty that I have is to create the folder only if it doesn't exist.

    Do U know how to implement it with SSIS script task ??

    Because I need to:

    1- Export data from my database filtered by Region and Month (because of files that I want to export )

    I think that I will use a ForeachLoop Container with SSIS DFT task inside it.

    And have Region and Month in parameter for the filter clause

    2- Create a folder with Month Name only if it doesn't exist (use script task or File system task ???)

    3- Create a sub-folder with Region Name only if it doesn't exist (use script task or File system task ???)

    4- Export Files in subfolder that I create .

    Please can U help me to implement it ???

  • Here is the code for a script task to check for the existence of c:\temp1. If it does not exist, it is created.

    public void Main()

    {

    string folderCheck = @"c:\temp1";

    if (!System.IO.Directory.Exists(folderCheck))

    System.IO.Directory.CreateDirectory(folderCheck);

    Dts.TaskResult = (int)ScriptResults.Success;

    }

    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.

  • Thank U Phil

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

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