Friday, January 14, 2011

How to zip/unzip files in Powershell?

I'm looking for an one-liner that will zip/unzip files (*.zip) in powershell

  • You may wish to check out http://www.codeplex.com/Pscx which has cmdlets specifically for this.

    marc_s : +1 PSCX is a great set of add-on cmdlets - I just wish I could pick and choose more which ones I want and which I don't. It seems to be changing a whole lot in my Powershell instance....
  • DotNetZip will allow you to do this from Powershell

    http://www.codeplex.com/DotNetZip

    Not a one-liner but the library will allow you to write the Powershell script you need.

    You can also use the COM interface

    http://blogs.msdn.com/daiken/archive/2007/02/12/compress-files-with-windows-powershell-then-package-a-windows-vista-sidebar-gadget.aspx

    Of course, I found this by googling "zip powershell" or "unzip powershell". Might want to try that as a resource too.

  • I find the simplest solution to just use infozip binaries which I have used for years and use in a UNIX environment.

    PS> zip -9r ../test.zip * 
    PS> cd .. 
    PS> unzip -t test.zip Archive:  test.zip
        testing: LinqRepository/          OK
        testing: LinqRepository/ApplicationService.cs   OK
        testing: LinqRepository/bin/      OK 
    ... 
    No errors detected in compressed data of test.zip.
    

    It would be straighforward to put a powershell wrapper around the text output but in practice I never need that so I haven't bothered.

    http://www.info-zip.org/

  • WinRAR can work in CMD mode accepting arguments

    From adopilot

0 comments:

Post a Comment