- <#
- .SYNOPSIS
- This script demonstrates the use of the Zip lib in .NET
- .DESCRIPTION
- This script is a re-write of an MSDN sample, using PowerShell
- .NOTES
- File Name : Show-ZIP.ps1
- Author : Thomas Lee - tfl@psp.co.uk
- Requires : PowerShell Version 3.0
- .LINK
- This script posted to:
- http://www.pshscripts.blogspot.com
- MSDN sample posted to:
- http://msdn.microsoft.com/en-us/library/system.io.compression.zipfile.aspx
- .EXAMPLE
- PSH> .\Show-Zip
- Directory: C:\example
- Mode LastWriteTime Length Name
- ---- ------------- ------ ----
- d---- 7/29/2013 4:35 PM extract
- d---- 7/29/2013 4:29 PM start
- -a--- 7/29/2013 4:35 PM 1668 result.zip
- Directory: C:\example\extract
- Mode LastWriteTime Length Name
- ---- ------------- ------ ----
- -a--- 7/29/2013 4:28 PM 5609 d1.txt
- -a--- 7/29/2013 4:29 PM 67308 d2.txt
- -a--- 7/29/2013 4:29 PM 67308 d3.txt
- -a--- 7/29/2013 4:29 PM 67308 d4.txt
- -a--- 7/29/2013 4:29 PM 67308 d5.txt
- Directory: C:\example\start
- Mode LastWriteTime Length Name
- ---- ------------ ------ ----
- -a--- 7/29/2013 4:28 PM 5609 d1.txt
- -a--- 7/29/2013 4:29 PM 67308 d2.txt
- -a--- 7/29/2013 4:29 PM 67308 d3.txt
- -a--- 7/29/2013 4:29 PM 67308 d4.txt
- -a--- 7/29/2013 4:29 PM 67308 d5.txt
- #>
- # Load the compression namespace
- # And yes, I know this usage is obsolete - but it works.
- # Ignore the output
- [System.Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem') | out-null
- # Set locations
- $startPath = "c:\example\start"
- $zipPath = "c:\example\result.zip"
- $extractPath = "c:\example\extract"
- Remove-Item $zipPath -ea SilentlyContinue
- Remove-Item -Path $extractPath -inc * -Recurse -ea SilentlyContinue
- # Create the zip file
- [System.IO.Compression.ZipFile]::CreateFromDirectory($startPath, $zipPath)
- # Extract from zip and show what's all there
- [System.IO.Compression.ZipFile]::ExtractToDirectory($zipPath,$extractPath);
- ls c:\example -Recurse
Technorati Tags: System.Io.Compression,ZipFile
No comments:
Post a Comment