Hi, here is the winrar method I use. I posted the 7-zip method previously, to me both are the same, although I prefer the 7-zip method over the winrar method.
' test.rar (is the name of the zip file to be created).
' ..\OUT\ (is the folder on your hard drive where all files with *_20100104.xls exist).
' *_20100104.xls (is the string used in winrar's include statement, only files with _20100104.xls in all subfolders will be included in rar file).
Copy the code below into Script Task of Visual Studio (BIDS).
Imports System.Data.OleDb
Imports System.IO
Imports Microsoft.SqlServer.Dts.Runtime
Public Class ScriptMain
Public Sub Main()
Dim InFolder, InFileType, OutFileName, OutExecutable, OutSubject, OutFolder, OutMessage As String
Dim FileDate, strDay, strMonth, strYear As String
InFolder = Trim(CStr(Dts.Variables("User::InFolder").Value))
OutFolder = Trim(CStr(Dts.Variables("User::OutFolder").Value))
InFileType = Trim(CStr(Dts.Variables("User::InFileType").Value))
strDay = Right("0" + CStr(Day(Now)), 2)
strMonth = Right("0" + CStr(Month(Now)), 2)
strYear = CStr(Year(Now))
FileDate = strYear + strMonth + strDay
OutFileName = "Customername" + FileDate + ".rar"
OutExecutable = " a -r test.rar ..\OUT\*_20100104.xls """ + OutFolder + OutFileName + """ """ + InFolder + "*." + InFileType + """"
OutSubject = "Daily Zipfile:- " + OutFileName
OutMessage = "Zip Successful"
Dts.Variables("User::OutExecutable").Value = OutExecutable
Dts.Variables("User::OutFileName").Value = OutFolder + OutFileName
Dts.Variables("User::OutSubject").Value = OutSubject
Dts.Variables("User::OutMessage").Value = OutMessage
Dts.TaskResult = Dts.Results.Success
End Sub
End Class