You are here:Home » tsql » Delete files from specified folder using File System Task in SQL Server - SSIS

Delete files from specified folder using File System Task in SQL Server - SSIS

We know all the various methods to delete the particular or all files from the specified folder using some of the methods like xp_delete_file, Ole Automation Procedures and with xp_cmdshell command line utility which we used for the old files archive or cleanup purpose. Here I am going to share some of the screens which delete the files with SSIS using File System Task. Let me share them one by one.

1. Folder having some test files,


2. Drag and drop Foreach Loop Container and File System Task. Foreach Loop Container used to get all the files inside that folder one by one and process with File System Task. Open the Foreach Loop Container properties, GOTO Collection tab and select Foreach File Enumerator as specified in the screen below.


3. Select the folder from where need to delete the files. Also apply extension if you need.


4. For the file assignment, we need one variable and the values allocated from the Foreach Loop Container process. So assign it from variable mapping as per shot taken below.



5. Drag File System Task, select Delete File operation and define Source Connection.



6. Finally, run package and files will get deleted.


Please write your comments.