.Net Framework 4.5のZipFileクラスとZipFileExtensionsクラスを使用して、開始する1つの方法を次に示します。
Add-Type -Assembly System.IO.Compression.FileSystem
foreach($sourcefile in (Get-ChildItem -filter "*.zip"))
{
Write-Host "Processing $sourcefile"
$entries = [IO.Compression.ZipFile]::OpenRead($sourcefile.FullName).Entries
#first pass to collect the paths of the folders with a Style.CSS file
$folders = $entries |
?{ $_.Name -eq 'Style.CSS' } |
%{ split-path $_.FullName } | unique
#second pass to extract just the files in those folders
$entries |
?{ (split-path $_.FullName) -in @($folders) -and $_.Name } |
%{
#compose some target path
$targetpath = join-path "$targetroot" (join-path $sourcefile.Name $_.FullName)
#create its directory
md (split-path $targetfilename) >$null 2>&1
#extract the file (and overwrite)
[IO.Compression.ZipFileExtensions]::ExtractToFile($_, $targetfilename, $true)
}
}
いくつかを定義するかtargetroot
、別のものを作成するだけtargetpath
です…</ p>