Style.CSS を含む特定のフォルダーのみを ZIP 抽出するための Powershell スクリプトが必要ですか?
フォルダーとファイルが混在する ZIP ファイルが多数あります。ZIP ファイルから Style.CSS を含む FOLDER 全体のみをフィルタリングして抽出するスクリプトが必要です。
DotNetZip を使用した同様のものがありますが、 Style.css を含む不明なフォルダー名を検出し、そのフォルダーのみを抽出するわけではありません。
お知らせ下さい。ありがとう。
Style.CSS を含む特定のフォルダーのみを ZIP 抽出するための Powershell スクリプトが必要ですか?
フォルダーとファイルが混在する ZIP ファイルが多数あります。ZIP ファイルから Style.CSS を含む FOLDER 全体のみをフィルタリングして抽出するスクリプトが必要です。
DotNetZip を使用した同様のものがありますが、 Style.css を含む不明なフォルダー名を検出し、そのフォルダーのみを抽出するわけではありません。
お知らせ下さい。ありがとう。
.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>
.NET 4.5 がオプションでない場合は、7zip を使用してください: http://sevenzip.sourceforge.jp/chm/cmdline/commands/extract.htm