Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

HOW TO CREATE DYNAMIC FOLDER TO INSERT EXPORTED FILES INTO ?? Expand / Collapse
Author
Message
Posted Thursday, June 06, 2013 10:02 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Monday, April 14, 2014 10:23 AM
Points: 63, Visits: 258
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.
Post #1460783
Posted Tuesday, June 11, 2013 1:46 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Thursday, March 06, 2014 11:38 PM
Points: 280, Visits: 215
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
Post #1461907
Posted Tuesday, June 11, 2013 5:00 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Monday, April 14, 2014 10:23 AM
Points: 63, Visits: 258
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 ???

Post #1461994
Posted Tuesday, June 11, 2013 6:23 AM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Today @ 4:25 AM
Points: 4,828, Visits: 11,184
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;
}




Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

When you ask a question (and please do ask a question: "My T-SQL does not work" just doesn't cut it), please provide enough information for us to understand its context.
Post #1462042
Posted Tuesday, June 11, 2013 2:18 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Monday, April 14, 2014 10:23 AM
Points: 63, Visits: 258
Thank U Phil
Post #1462373
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse