Extract Specific Files from ZIP Archive in an ZIP Archive

Welcome Forums General PowerShell Q&A Extract Specific Files from ZIP Archive in an ZIP Archive

Viewing 1 reply thread
  • Author
    • #277116
      Topics: 1
      Replies: 0
      Points: 14
      Rank: Member

      My Ex. Archive:

      — 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)

      I would like to extract the file “file_3.txt” directly from the second zip archive
      without extract the second archive before
      • This topic was modified 1 month, 2 weeks ago by saeckl90.
    • #277341
      Topics: 17
      Replies: 1951
      Points: 3,987
      Helping Hand
      Rank: Community Hero

      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.

Viewing 1 reply thread
  • You must be logged in to reply to this topic.