Getting Started with Adobe After Effects - Part 6: Motion Blur

Upload Image Close it
Select File

Towards the innovative SQL ideas
Browse by Tags · View All
sql server 125
sql 124
ms sql server 119
ms sql 118
database 109
tsql 81
#SQL Server 78
t-sql 75
#sql 71
sql server general 67

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
September 2013 5
June 2013 5

SSIS - Delete files older than retention period from specified folder using Script Task in SQL Server

Feb 4 2012 12:00AM by Paresh Prajapati   

Earlier we have seen for the Delete file using Script Task and files deletion using File System Task in SSIS. We have directly wrote the logic to get the files and delete from specified folder in the script for the Script Task. For File System Task we have Used Foreach Loop Container and variables to hold file names which are passed from earlier stage one by one and then finally used with File System Task to delete it.

Here we have same but not to delete all the files inside passed folder but get deleted files which are older than specified days. This is nothing but minor change in script where we pass the folder path and retention period. Lets start the steps as following,

1. Let check the files from the target folder.

2. Drag and drop Script Task.

3. Open script editor from the properties.

4. Apply attached script in editor which have additional logic with condition to check the file lat modified date and check if older than specified retention period or not.

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

5. Turn on final step and run package. Files older than specified retention period 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
int RetentionPeriod = 3;
string directoryPath = @"E:\ImagesBackup";
string[] oldFiles = System.IO.Directory.GetFiles(directoryPath, "*.png");
     foreach (string currFile in oldFiles)
                FileInfo currFileInfo = new FileInfo(currFile);
                if (currFileInfo.LastWriteTime < (DateTime.Now.AddDays(-RetentionPeriod)))

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, retention,

Paresh Prajapati
6 · 23% · 7544
6 Readers Liked this
Paresh Prajapati Liked this on 2/4/2012 7:32:00 AM
Profile · Blog · Facebook · Twitter
Jacob Sebastian Liked this on 2/19/2012 9:23:00 AM
Profile · Blog · Facebook · Twitter
Guru Samy Liked this on 3/5/2012 6:33:00 AM
Profile · Blog
krunal Liked this on 3/27/2012 3:09:00 AM
Profile · Facebook
Nirav Liked this on 3/28/2012 12:21:00 AM
Profile · Blog · Facebook · Twitter
Kirti M.Darji Liked this on 4/16/2012 4:24:00 AM
Profile · Blog · Facebook · Twitter


Your Comment

Sign Up or Login to post a comment.

"SSIS - Delete files older than retention period from specified folder using Script Task in SQL Server" rated 5 out of 5 by 6 readers
SSIS - Delete files older than retention period from specified folder using Script Task in SQL Server , 5.0 out of 5 based on 6 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]