none
Zip Files - Size Difference in creating one with GUI vs Powershell and .NET Framework 4.5 RRS feed

  • General discussion

  • My question is in relation to the following article on scripting guy forum:

    blogs.technet.com/b/heyscriptingguy/archive/2015/03/09/use-powershell-to-create-zip-archive-of-folder.aspx

    I noticed when creating a zip file with this method, The compression method is Deflated, yet when compressing with the GUI it is Deflated 64. The end result being a more compressed file with the GUI than the script. Is there a way to change this to Deflated 64 in the PowerShell script?

    Here's the compression portion of the script. Files are text files that range between 256MB to up to 1GB.
    $FileList | ForEach-Object -Begin {
        $Zip = [System.IO.Compression.ZipFile]::Open("$Destination","Create")
        } -Process {
        [System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile($Zip,$_.FullName,$_.Name,"optimal")
        } -End {
        $Zip.Dispose()
        }


    Tuesday, December 22, 2015 6:21 PM

All replies

  • [System.IO.Compression.CompressionLevel]::Optimal

    [io.compression.zipfile]::CreateFromDirectory($Source,$destination,'Optimal')


    \_(ツ)_/

    Tuesday, December 22, 2015 6:48 PM
  • I did use this in my script. Which is why I asked the question the way I did. In PowerShell the method used is Deflated. Even with the Optimal parameter.

    Here's a snippet of code currently in use for the compression. However the GUI still compresses much better than the script.

    $FileList | ForEach-Object -Begin {
        $Zip = [System.IO.Compression.ZipFile]::Open("$Destination","Create")
        } -Process {
        [System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile($Zip,$_.FullName,$_.Name,"optimal")
        } -End {
        $Zip.Dispose()
        }

    Tuesday, December 22, 2015 7:02 PM
  • That is all we get with net classes.

    \_(ツ)_/

    Tuesday, December 22, 2015 7:20 PM
  • That is all we get with net classes.

    \_(ツ)_/


    I take it there isn't another option besides .Net to attempt doing this with?
    Tuesday, December 22, 2015 7:22 PM
  • Dozens of options.  PkZip, WinZip, GZip, tar. 7Zip.....

    \_(ツ)_/

    Tuesday, December 22, 2015 7:28 PM
  • Let me rephrase. No other options without using third party tools?
    Tuesday, December 22, 2015 7:32 PM
  • didn't try it myself, but take a look at this approach, uses the windows api

    http://stackoverflow.com/questions/11021879/creating-a-zipped-compressed-folder-in-windows-using-powershell-or-the-command-l

    Tuesday, December 22, 2015 8:18 PM
  • didn't try it myself, but take a look at this approach, uses the windows api

    http://stackoverflow.com/questions/11021879/creating-a-zipped-compressed-folder-in-windows-using-powershell-or-the-command-l

    Using the shell this way isn't a great idea, it's not meant for automation.

    It might work, but it'll behave strangely sometimes.


    Tuesday, December 22, 2015 8:27 PM
  • didn't try it myself, but take a look at this approach, uses the windows api

    http://stackoverflow.com/questions/11021879/creating-a-zipped-compressed-folder-in-windows-using-powershell-or-the-command-l

    Using the shell this way isn't a great idea, it's not meant for automation.

    It might work, but it'll behave strangely sometimes.



    If I remember correctly, the problem is that you have to add a  Start-sleep command and will definitely cause errors if you underestimate the time it takes to compress each file.
    Tuesday, December 22, 2015 8:34 PM
  • The shell relies on events to manage compression.  PowerShell has not been able to intercept those events.  It can be ade to work for a small number of small files but nearly always has issues with larger and larger numbers of files.


    \_(ツ)_/

    Tuesday, December 22, 2015 8:34 PM