Jay C
Jay C

Reputation: 872

Copy Directories with SSIS

I am using SSIS with Visual Studio 2012.

I am using variables to make folders and folders within folders.

The parent folder is static VarFolderPath = c:\Source\test\

the first subdirectory within it is dynamic based on yyyymm. I use the following expression to make this folder stores in the variable VarFolderName.

@[User::VarFolderPath]+RIGHT("0" + (DT_STR, 4, 1252) DATEPART("yy" , GETDATE()), 4) +  (DT_STR, 2, 1252) DATEPART("mm" , GETDATE())

Within VarFolderName I then make four other folders CLI, Day3, INF, PRI. That is all working

Make Folders

I then want to copy CLI, INF, and PRI within the Day3 folder. I want two versions of CLI, INF and PRI. Oned irectly in VarFolderName, and another in Day3. I could make more variables to accomplish this, but since I already made the directories I was hoping to copy them. However using File System Task > Copy Directory does not copy folders, it copies all files within folders.

Thus other than adding three additional variables is there a way to leverage the directories I have already made (CLI,INF, PRI) and place copies of them in Day3 shown as numbers 5,6,7 below.

Upvotes: 0

Views: 1573

Answers (2)

Ben Gribaudo
Ben Gribaudo

Reputation: 5147

What about using xcopy via an Execute Process Task?

To do this, configure the task with Executable set to cmd.exe and Arguments equal to /C followed by the full command line you want to execute. For example, to copy the PRI directory to Day3\PRI, with destination directories created as needed, use /C xcopy /I /E PRI Day3\PRI.

If you'd like to use a single Execute Process Task to copy all three directories, try Arguments of \C xcopy /I /E CLI Day3\CLI & xcopy /I /E INF Day3\INF & xcopy /I /E PRI Day3\PRI.

Upvotes: 1

Mark Wojciechowicz
Mark Wojciechowicz

Reputation: 4477

The file system task is pretty limited in SSIS - it is really intended for the most basic operations. Even with what you have so far, it is getting a bit complicated compared to what you could do in a script task. Please check out this code example and try rewriting this in c# or vb:

http://msdn.microsoft.com/en-us/library/bb762914(v=vs.110).aspx

Upvotes: 0

Related Questions