Wednesday, September 27, 2006

 

Unzip your files

I really don't like the unzip feature that comes with the Windows shell. Terribly slow if there are many files in the arrchive.
I also don't like 7zip, which I've seen used around. It frequently isn't able to read zip files.
I do like ICSharpCode.SharpZipLib, an open-source compression library.

Here's a little PowerShell script that will extract zip files for you:

Param($source, $destination=".")

$sourceFile = get-item $source
$destDir = get-item $destination

function using-library {
param($ns = $(throw "Enter Namespace to import"), [bool]$SuppressOutput = $false)

trap { throw "Could not import Namespace $($ns)" }

if ($SuppressOutput) {
[void][System.Reflection.Assembly]::LoadWithPartialName($ns)
} else {
[System.Reflection.Assembly]::LoadWithPartialName($ns)
}
}


using-library "ICSharpCode.SharpZipLib" $true

$unzip = new-object ICSharpCode.SharpZipLib.Zip.FastZip
$unzip.ExtractZip($sourceFile.FullName, $destDir.FullName, "Always", $null, "", "")

You'll have to add the assembly to the GAC. Open a Visual Studio SDK command window and type the command,

c:\>gacutil /i <path_to_ICSharpCode.SharpZipLib.dll>


Also, notice that in this script I am still instantiating objects using fully-qualified names. Can anyone tell me how to import namespaces into the global symbol table within a PowerShell script?

Comments:
I've been exploring for a little for any high-quality articles or weblog posts on this sort of area . Exploring in Yahoo I ultimately stumbled upon this web site. Studying this info So i am glad to express that I've a very good uncanny feeling I found out exactly what I needed.
I most undoubtedly will make sure to do not disregard this website and give it a look on a continuing basis.



Here is my web-site; Arabic Books
 
Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?