question

palum avatar image
palum asked

create directory structure dynamically

I have a table which has 2 coloumns Class and RollNo. Class(varchar) RollNo(int) Class1 101 Class2 104 Class1 116 class5 304 I want to create the below directory structure in my shared location like \\disk1\pathxyz\Class1\101 \\disk1\pathxyz\Class2\104 \\disk1\pathxyz\Class1\116 \\disk1\pathxyz\Class5\304 Note:Class1 folder will have 2 subfolders 101,116 Any ideas how this can be done using Script task in SSIS?
ssisscriptc#
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Valentino Vranken avatar image
Valentino Vranken answered
Why would you want to use a script task? It can be done fairly easily using the Foreach Loop container to loop over your folders to be created. Here's what I'd do: 1. Create a **Execute SQL task** (Control Flow) that retrieves your data into a package variable 2. Attach a **Foreach Loop** to loop over the ADO recordset 3. Inside the Foreach Loop, use one or several **File System tasks** to create the folders as expected. You could have one that creates the *Class* folder, followed by another one that creates the *RollNo* subfolder. For more details on how to loop over a dataset in SSIS, please refer to the following article: [ http://www.select-sql.com/mssql/loop-through-ado-recordset-in-ssis.html][1] [1]: http://www.select-sql.com/mssql/loop-through-ado-recordset-in-ssis.html
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.