--// 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 = Convert.ToInt32(Dts.Variables["User::Period"].Value.ToString()); string directoryPath = Dts.Variables["User::BackupFolder"].Value.ToString(); string[] oldFiles = System.IO.Directory.GetFiles(directoryPath, "*.*"); foreach (string currFile in oldFiles) { FileInfo currFileInfo = new FileInfo(currFile); if (currFileInfo.LastWriteTime < (DateTime.Now.AddDays(-RetentionPeriod))) { currFileInfo.Delete(); } }
Tags: sql, sql server, ms sql, ms sql server, #SQL Server, #sql, database, sql server general, SQL Scripts, SSIS, SSDT, retention,