Welcome › Forums › General PowerShell Q&A › Extract Specific Files from ZIP Archive in an ZIP Archive
- This topic has 1 reply, 2 voices, and was last updated 1 month, 1 week ago by
Participant.
-
AuthorPosts
-
-
December 7, 2020 at 6:38 am #277116
My Ex. Archive:
.\Desktop\Archive.zip
–second.zip
— file_3.txt
— file_1.txt
— file_2.txt$Path = “$Home\Desktop\Archive.zip”
$Filter = ‘second.zip’
$OutPath = ‘C:\Tmp’
$exists = Test-Path -Path $OutPath
if ($exists -eq $false)
{
$null = New-Item -Path $OutPath -ItemType Directory -Force
}
Add-Type -AssemblyName System.IO.Compression.FileSystem
$zip = [System.IO.Compression.ZipFile]::OpenRead($Path)
$zip.Entries |
Where-Object { $_.FullName -like $Filter } |
ForEach-Object {
$FileName = $_.Name
[System.IO.Compression.ZipFileExtensions]::ExtractToFile($_, “$OutPath\$FileName”, $true)
}
$zip.Dispose()I would like to extract the file “file_3.txt” directly from the second zip archivewithout extract the second archive before-
This topic was modified 1 month, 2 weeks ago by
saeckl90.
-
This topic was modified 1 month, 2 weeks ago by
-
December 7, 2020 at 2:07 pm #277341
Not sure that you can extract a file that is compressed in another file without opening the parent file. That’s like unbuttoning your shirt with your jacket zipped up. Assuming you are getting the core code from here:
As you can see in that example and in your code above, those are zip entries, not the actual files. In order to access the .ZIP file, it appears it has to be extracted first. Once you open Archive.zip, extract Second.zip, open Second.zip and extract file3, you can remove second.zip from the extracted path to cleanup.
-
-
AuthorPosts
- You must be logged in to reply to this topic.