question

Mrs_Fatherjack avatar image
Mrs_Fatherjack asked

Zip files using XP_cmdshell

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.
ssisxp_cmdshellzip-file
1 comment
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

what zip software you using? The standard windows compression?
0 Likes 0 ·
Tim avatar image
Tim answered
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
2 comments
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Kev Riley avatar image
Kev Riley answered
Have you seen this SSC article? Linked from a similar question here
2 comments
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

I found that but the script task is in .net and I don't have that as an option on my script task editor, I only have C# and VB, any ideas on that? Thanks
0 Likes 0 ·
I think the article was written when the only script language available was VB.net, whereas now you have the choice between VB and C#. To follow the article I would use VB
0 Likes 0 ·
aRookieBIdev avatar image
aRookieBIdev answered
I used this to do the same in my SSIS package. Hope this is useful.Thanks http://dotnetzip.codeplex.com/
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

kevchant avatar image
kevchant answered
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"
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.