Can anyone please advise me on the command to zip files using xp_cmdshell. I need to zip files from within an SSIS package and thought this may be the easiest route. Any other ideas greatfully received Many thanks.
I use the built in windows compress files and folders option and call it with VB. This code snippet has served me very well and is commented very nicely so you should be able to plug in your values. 'Create the Shell.Application object Dim oShellApp, oFSO, oWScript Set oShellApp = CreateObject("Shell.Application") 'Create the File System object SET oFSO = CreateObject("Scripting.FileSystemObject") DIM sZipFile sZipFile = "d:\public\folder\zipfile\filename.zip" sTargetFolder = "d:\public\folder" oFSO.CreateTextFile sZipFile, True '.Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar) oShellApp.NameSpace(sZipFile).CopyHere oShellApp.NameSpace(sTargetFolder).Items(),1556 SET oShellApp = nothing SET oFSO = nothing
Just in case you want an alternative one option is to create a script which uses the winrar command line utility to regularly compress all Backups within a folder. E.g. for %%I in (c:\Backups\Logs\*.*) do "C:\Program Files\WinRAR\winrar" A -df -m5 "c:\Backups\Logs\%%~nI.rar" "%%I“ Just in case this is for a file transfer, to extract the files that have been compressed by Winrar once copied to their destination you could extract using the UnRAR command line tool. E.g. for %%I in (C:\Backups\Logs\*.rar) do "C:\Program Files\WinRAR\unrar" e -o- "%%I" "C:\Backups\Logs"