I have a zipfile with a random filename that is enclosed within a randomly-named zipfile. I am refining the following sample code:
$shell = new-object -com shell.application
$zip = $shell.NameSpace(“C:\howtogeeksite.zip”)
foreach($item in $zip.items())
{
$shell.Namespace(“C:\temp\howtogeek”).copyhere($item)
}
The outer zipfile contains a few hundred files I don't need plus this one zipfile inside it- How do I refine the above source code to only grab the inner zip file (It could just extract all files from the outer zipfile whose extension is .zip)... Please advise the easiest way to do this. Thanks!
You need to iterate over the contents checking if the file extension of each item is ".zip" before extracting. Something like this should work:
$shell = new-object -com shell.application
$zip = $shell.NameSpace(“C:\howtogeeksite.zip”)
foreach($item in $zip.items()){
if([System.IO.Path]::GetExtension($item.Path) -eq ".zip"){
$shell.Namespace(“C:\temp\howtogeek”).copyhere($item)
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With