extract nested archives to get content

Viewed 730

I have nested archives that am trying to extract, it has following format so archive1.zip is main other archives are nested inside each other I need to get folder directory extracted.

  • archive1.zip/
    • archive2.tar/
      • archive3.7z/
        • folder/
          • file.txt

I tried the following :

Get-ChildItem -Path $path -Recurse | ForEach-Object { $_.FullName } | Split-Path | Get-Unique |

ForEach-Object { cd $_; 7z x * -r -aou  -o"$path" }

But I can only get archive2.tar as output

1 Answers

I managed to do it by using a loop as follows extracting archive then deleting it and so on.

$files = Get-ChildItem -Path $path
$extension = ".tar|.zip|.7z"

1..3 | % {

$zip = Get-ChildItem -Path $path -File  | where {$_.Extension -match $extension} | ForEach-Object { $_.Name }
$files | ForEach-Object { $_.FullName } | Split-Path | Get-Unique |
ForEach-Object { Set-Location $_; 7z x * -aou -o"$path"; Remove-Item $zip}

}
Related