December 11, 2007 at 4:43 am
Do you have to create a separate Maintenance Cleanup Task in order to delete each type of file e.g .txt, .bak, .trn etc?
December 11, 2007 at 8:19 am
Yes. The alternative would be to create an SSIS package for maintenance operations in BIDS and use a script task to delete files, i.e.
Imports System.Data
Imports System.Math
Imports System.IO
Imports Microsoft.SqlServer.Dts.Runtime
Public Class ScriptMain
Public Sub Main()
Dim strFile As String, strFilePath As String
strFilePath = Dts.Variables("varBackupLocation").Value
Dim strFileNames = Directory.GetFiles(strFilePath)
Try
For Each strFile In strFileNames
Dim FileInfo As New System.IO.FileInfo(CStr(strFile))
'For Debug
'System.Windows.Forms.MessageBox.Show(FileInfo.CreationTime)
'System.Windows.Forms.MessageBox.Show(FileInfo.CreationTime < DateTime.Now.AddDays(-3))
If (FileInfo.CreationTime <= DateTime.Now.AddDays(-3)) = True Then
File.Delete(strFile)
End If
Next
Catch ex As Exception
End Try
Dts.TaskResult = Dts.Results.Success
End Sub
End Class
Tommy
Follow @sqlscribeDecember 11, 2007 at 9:25 am
Thanks for the response. Have implemented it and it works well.
December 11, 2007 at 9:29 am
NP 😀
Tommy
Follow @sqlscribeViewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply