Monday 10 June 2013

SSIS File System Task

Introduction

In this article I am trying to discuss about a beautiful and widely used task in SSIS control flow and it is called the File System Task. Most of the SSIS developer prefers these tasks to work with file systems.  So I decide to put it in my article list.

What the use of File System Task
As the name suggest the file system tasks is used to work with file system such as Copy or Move file from one location to another, Delete files and directories, Rename etc. It can work with attributes like hidden, archive, read-only etc.

To perform this type of operation on source and destination it needs file connection manager configuration or a variable that contain the respective path.

Limitation of File System Task
With lot of facilities provided by File System Task, it has certain limitation that we must understand. The File system tasks can only open a single file or directories. Therefore it cannot be used with multiple file or directories.

Don't worry; there is a solution for that. To do so we have to put the File System Task into Foreach Loop Containers.

Operation by File System Tasks

Here is a list of predefine operation that can be performed by File System Task.

Operation
Description
COPY
Directory
To copy a folder from one location to other.
File
Copies a file from one location to other.
DELETE
Directory
To delete a folder in a specific location.
File
Deletes a file in a specific location.
MOVE
Directory
To move a folder from one location to other.
File
Moves a file from one location to other.
RENAME
File
Renames a file in a specified location.
CREATE
Directory
Creates a folder in a specified directory.
SET ATTRIBUTES
Files or Folder
Attributes of a file or folder includes Normal, Hidden, Read-only.

Example of File System Task

Step-1 [ Create a Package level Variable ]

We care a package level variable first which contain the source path.



Variable Name: v_SourcePath
Data Type        : String
Scope               : Package Level
Value                 : F:\Practice_SQL\SSIS\FileSystemTask\SourceFolder\SourceFile.txt

Please Note that the File name is very important here with Path of the folder others we got an error.



Step-2 [ Drag the File System Task to Control Flow pan ]

Now we are configuring the file system task editor.







Step-3 [ Run the Package and Analyze the Output ]







Hope you like it.




Posted by: MR. JOYDEEP DAS

3 comments:

  1. HI JOY,
    Nice once. Still lot of options are available in File System Task, Like for example: i have a 2 FOLDERS
    1.SOURCE FOLDER
    2.DESTINATION FOLDER

    FOR a incremental ETL we are loading data from the source folder.Once data has been loaded into respective DWH Tables then we need to take a Backup of source Data into some other location(DESTINATION FOLDER)

    ReplyDelete
  2. Very helpful article. After reading the article I have a question for you, What is the procedure to copy multiple files in destination folder? Is it possible to do this using a foreach loop?

    ReplyDelete
  3. How to work with foreach loop container..??

    ReplyDelete