Description – File system task is used to execute operations such as copy, move or delete files and directories from one location to other. We can also set the attributes like hidden, archive, read-only etc of specific files and directories. To perform operations like copying, moving, deleting etc for a file or directory requires a Source and Destination which can be configured by using a File connection manager or by providing a variable that contains the respective path.
Source – It is the location from where you want to move, rename, and copy a file or directory.
Destination – It is the location at which the selected file or directory is moved, renamed, copied.
NOTE :- File system task operates on single file or directory. Therefore, to repeat File system task on multiple files or directories, put it in a Foreach Loop Container and configure it. To learn how to configure Foreach Loop Container, Visit – Implementation of Foreach Loop Container.
FILE SYSTEM TASK PREDEFINED SET OF OPERATIONS
||To copy a folder from one location to other.
||Copies a file from one location to other.
||To delete a folder in a specific location.
||Deletes a file in a specific location.
||To move a folder from one location to other.
||Moves a file from one location to other.
||Renames a file in a specified location.
||Creates a folder in a specified directory.
||Files or Folder
||Attributes of a file or folder includes Normal, Hidden, Read-only, Archive and System.#These attributes can be used in combination except Normal.
Example Scenario: – We will create one package to move a folder from one directory (C:\Chander-Source) to other location (C:\Chander-Destination) using one of the File system task operations (Move directory operation).
STEPS TO FOLLOW:-
Step 1. Open Business Intelligence Studio and Create one package with desired name (cK_File_System_Task.dtsx ).
Step 2. Right click on the Control flow pane and select Variables (we need a variable to store the Source path). Once the window is open, click the Add Variable button and specify the fields as:-
- Name – Any desired name say Sourcepath.
- Data Type – String as we have to store the path of a variable.
- Namespace – User as it is user defined variable. It can be either User or System.
- Scope – Package level as it will be for whole package.
- Value – C:\Chander-Source i.e. Path of the Source folder.
Step 3. Drag and drop the File System task from the toolbox onto Control flow pane.
Step 4. You will see the red icon with a cross as it is not configured yet. Double-click it to open the File System Task Editor and in General Tab specify the fields as:-
- Name – Move Folder.
- Description – Moving a folder from one directory to other.
- IsSourcePathVariable – True as we have stored the path in a variable named Sourcepath. It can also be either true or false as in the case of IsDestinationPathVariable.
- SourceVariable – User:Sourcepath from the dropdown box.
- Operation – Move directory as we are performing a move operation.
- IsDestinationPathVariable – False as the path is static. It can be either true or false but if it is true then the path will be stored in a variable.
- DestinationConnection – Choose the destination folder path from the dropdown, where we need to move our selected file (in this case it’s – C:\Chander-Destination).
- OverwriteDestination – True as file already exists in the directory. If we will choose False for this then we will get the following error message – [File System Task] Error: An error occurred with the following error message: “Cannot create a file when that file already exists”.
Step 6. Now, click on OK button and execute the package.
With this we completes our implementation of Moving files from one directory or location to other directory or location. I hope this validates your concept on File System Task in SSIS. We can use this File system task for various operations such as Create, delete, move, copy, etc. Your views and comments are valuable.
VN:F [1.9.22_1171]Move files from one directory to other using File System Task in SSIS,