Folding a folder (for example, creating an uncompressed zip code) from PowerShell

I make an overnight backup of all files modified on the last day using PowerShell.

The goal is to create an uncompressed zip (or any other format) that will group everything into a backup folder into a single file using PowerShell.

The following code is great for compression, but it's too slow:

function Add-Zip
{
    param([string]$zipfilename)

    if(-not (test-path($zipfilename)))
    {
        set-content $zipfilename ("PK" + [char]5 + [char]6 + ("$([char]0)" * 18)) 
        (dir $zipfilename).IsReadOnly = $false  
    }

    $shellApplication = new-object -com shell.application
    $zipPackage = $shellApplication.NameSpace($zipfilename)

    foreach($file in $input) 
    { 
        $zipPackage.CopyHere($file.FullName)
        Start-sleep -milliseconds 1000
        #500 milliseconds was too short.... 
    }
}

Any ideas?

Thank!

+3
source share
3 answers

I would recommend using powershell in conjunction with the 7-Zip command line. 7-Zip has a command line option that allows no compression.

-mx0
+5
source

PowerShell Write-Tar, .

+4

Eld answer , :

function ZipFiles( $zipfilename, $sourcedir )
{
   [Reflection.Assembly]::LoadWithPartialName("System.IO.Compression.FileSystem")
   $compressionLevel = [System.IO.Compression.CompressionLevel]::NoCompression
   [System.IO.Compression.ZipFile]::CreateFromDirectory($sourcedir,
        $zipfilename, $compressionLevel, $false)
}

Eld also talks about his decision, which also applies here:

A clean Powershell alternative that works with Powershell 3 and .NET 4.5 (if you can use it):

From his answer was to indicate NoCompressioninstead Optimalfor the level.

0
source

All Articles