# Author: DBMwSIt is still not complete since, it does not list a zip file inside a given zip file name(no recursive listing)
# Date: 02/27/2006 @ 04:13 PM EST
# Description: Retrieve a Zip file's content
# (either display only files inside the zip file or return ZipEntry object)
# Note: This function requires J# Library, "vjslib"
# Usage: get-ZipContent file_name [[System.Bool] -toString]
# Reference: http://codeproject.com/csharp/VmEasyZipUnZip.asp
# Params
# 1) $zipFileName: Path of zip file
# 2) $toString: return name of zip content, otherwise return ZipEntry
function Get-ZipContent {
param($zipFileName = $(throw "Enter Zip File Name"), [bool]$toString = $true)
# Load J# library
# used "out-null" instead of "[void]" since "out-null" would not display
# loaded assembly even if there was an exception thrown
[System.Reflection.Assembly]::LoadWithPartialName("vjslib") | out-null
# 1) Open "java.io.FileInputStream" for a zip file
$fis = new-object java.io.FileInputStream($zipFileName)
# 2) Pipe File Input stream object to "java.io.ZipInputStream"
$zis = new-object java.util.zip.ZipInputStream($fis)
# 3) While there exists a content in a zip input stream, get a content of type "ZipEntry"
while (($ze = $zis.getNextEntry()) -ne $null) {
if ($toString) {
# Pass string value to pipe
Write-Object $ze.ToString()
} else {
# Pass actualy ZipEntry object to pipe
$ze
}
}
# 4) Close "ZipInputStream" first and then "FileInputStream"
$zis.close()
$fis.close()
trap {
if ($zis -ne $null) { $zis.close() }
if ($fis -ne $null) { $fis.close() }
break
}
}
MSH>ls | where {!$_.MshIsContainer -and $_.name -like "*.zip"} | foreach { get-zipcontent $_.fullname } | where { $_ -like "*.jpg" }
Experimenting with a different format of blogs...