Getting Started with ASP.NET MVC - Part 5: How to do programming with razor syntax
First Time? You can support us by signing up. It takes only 5 seconds. Click here to sign up. If you already have an account, click here to login.


Upload Image Close it
Select File

Towards the innovative SQL ideas
Browse by Tags · View All
ms sql server 97
ms sql 93
sql server 89
sql 88
database 75
#SQL Server 75
tsql 65
#sql 62
t-sql 59
sql server general 56

Archive · View All
April 2011 14
July 2011 12
May 2011 12
August 2011 11
June 2011 10
September 2011 8
December 2011 6
November 2011 6
February 2012 5
April 2012 4

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

Dec 30 2011 8:13AM by Paresh Prajapati   

Earlier we have seen for the files deletion using File System Task in SSIS. We have used it with Foreach Loop Container. Used a variable to hold file names which are passed from earlier stage one by one and then finally used with File System Task to delete it.

Now i am going to use Script Task to delete all files from specified folder. Here i have added script to get each files from specified folder and then delete them as you can see in the following steps. Lets start to follow them.

1. Drag and drop Script Task.














2. Open script editor from the properties.































3. Apply attached script in editor and save it.



















Please note here we need to import system.IO namespace.

4. Turn on final step and run package. Files get deleted.

























You can also find script code here, 

--// You need to apply below one line in "namespaces" region.
using System.IO;

--//You need to apply below lines inplace of  // TODO: Add your code here

 string directoryPath = @"E:\TestFolder";
            string[] oldFiles = System.IO.Directory.GetFiles(directoryPath, "*.txt");
            foreach (string currFile in oldFiles)
            {
                FileInfo currFileInfo = new FileInfo(currFile);
                currFileInfo.Delete();
              
            }


Hope you liked this post. Stay tuned for more.

Tags: sql, sql server, ms sql, ms sql server, #SQL Server, #sql, database, sql server general, SQL Scripts, SSIS, SSDT,


Paresh Prajapati
7 · 24% · 5483
2
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

Your Comment


Sign Up or Login to post a comment.

"SSIS - Delete files from specified folder using Script Task in SQL Server" rated 5 out of 5 by 2 readers
SSIS - Delete files from specified folder using Script Task in SQL Server , 5.0 out of 5 based on 2 ratings
    Copyright © Beyondrelational.com Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising