Aug 2, 2016

Move Files from one folder to another folder in SSIS

Problem: Suppose we have a source directory where more than one tab delimited files exists and we need to move files in archive folder one by one after read and transform the data from these files.

Solution: SSIS is the best option for this operation. We can use foreach loop container to get files one by one to perform the operation. In this article I am explaining only how to move files from one directory to another directory.

Step 1: Drag and drop ForEach loop container from tool to control flow.

Step 2: Create to variable at package level. 1- Destination 2- FileName

Note: Set the value of Destination (path of destination folder).
Step 3: Right click on ForEach Loop Container and click on edit.

In General option you can change the name of container.
Step 4: Click on Collection tab in editor wizard and brows the source folder.

Note: in file option you can set file extension mean if you want to read and move .txt file only from the source folder.

Step 5: This step is important, click on Variable mapping Tab, in variable option choose FileName variable and set index zero.

Now everything is fine click on OK button.
Step 6: Drag and drop File System Task within Foreach Loop Container.

Step 7: Right click and Edit File System Task. There you will find many options.

1-  Destination Connection: Select true option for IsDestinationPathVariable and select Destination (user variable) option for DestinationVariable. 
    2-  General: Here you can set the name of file system task.
   3-  Operation: This is important, there are many options, and you can chose option as per your objectives. We will choose option Move file.
  4-Source Connection: Choose <New Connection> as below. You can choose existing connection also. 
  5-Now source connection created, right click on source connection and select property option.

g  7-The property will open and click on expression a window will open choose option ConnectionString and click on side button a new expression window will open choose FileName variable and click on OK.


Now you package is ready execute package and enjoy.