File System Task in SSIS with Real-Time Scenarios
The File System Task in SSIS is used to perform file and folder operations such as copying, moving, deleting, renaming, and setting file attributes. It is commonly used in ETL (Extract, Transform, Load) processes to manage files before or after data processing.
Key Features of the File System Task
Operations Supported:
Copy – Copy a file/folder to a new location.
Move – Move a file/folder to a new location.
Delete – Remove a file/folder.
Rename – Change the name of a file/folder.
Create Directory – Make a new folder.
Set Attributes – Modify file attributes (Read-only, Hidden, etc.).
Works with:
Local files
Network shared files (UNC paths)
FTP/SFTP (when combined with other tasks)
No data transformation – Only file/folder manipulation.
Real-Time Scenarios for File System Task
1. Moving Processed Files to an Archive Folder
Scenario: After extracting data from a CSV file, move it to an archive directory to avoid reprocessing.
Solution: Use the File System Task with Move operation.
Configuration:
Operation: Move file
Source Connection:
C:\ETL\Source\sales_data.csv
Destination Connection:
C:\ETL\Archive\sales_data_20240501.csv
Usage: After the Data Flow Task that processes the file.
2. Deleting Old Log Files
Scenario: Log files older than 30 days should be removed to save disk space.
Solution: Use a Script Task to identify old files + File System Task to delete them.
Configuration:
Operation: Delete file
Source Connection:
C:\Logs\*.log
(with a ForEach Loop to iterate files)Condition: Delete if
LastModifiedDate < (Today - 30 days)
3. Copying a File Before Processing (Backup)
Scenario: Before processing a file, create a backup copy in case of failures.
Solution: Use File System Task to Copy the file.
Configuration:
Operation: Copy file
Source:
\\Shared\Incoming\orders.xlsx
Destination:
\\Shared\Backup\orders_backup.xlsx
Usage: Before the Data Flow Task that reads the file.