Say foo.zip
contains:
a
b
c
|- c1.exe
|- c2.dll
|- c3.dll
where a, b, c
are folders.
If I
Expand-Archive .\foo.zip -DestinationPath foo
all files/folders in foo.zip
are extracted.
I would like to extract only the c
folder.
Say foo.zip
contains:
a
b
c
|- c1.exe
|- c2.dll
|- c3.dll
where a, b, c
are folders.
If I
Expand-Archive .\foo.zip -DestinationPath foo
all files/folders in foo.zip
are extracted.
I would like to extract only the c
folder.
try this
Add-Type -Assembly System.IO.Compression.FileSystem
#extract list entries for dir myzipdir/c/ into myzipdir.zip
$zip = [IO.Compression.ZipFile]::OpenRead("c:\temp\myzipdir.zip")
$entries=$zip.Entries | where {$_.FullName -like 'myzipdir/c/*' -and $_.FullName -ne 'myzipdir/c/'}
#create dir for result of extraction
New-Item -ItemType Directory -Path "c:\temp\c" -Force
#extraction
$entries | foreach {[IO.Compression.ZipFileExtensions]::ExtractToFile( $_, "c:\temp\c\" + $_.Name) }
#free object
$zip.Dispose()
$zip.Entries | Where-Object { $_ -match 'myzipdir/c/+.' }
–
Blenny This one does not use external libraries:
$shell= New-Object -Com Shell.Application
$shell.NameSpace("$(resolve-path foo.zip)").Items() | where Name -eq "c" | ? {
$shell.NameSpace("$PWD").copyhere($_) }
Perhaps it can be simplified a bit.
Here is something that works for me. Of Course, you will need to edit the code to fit your objective
$results =@()
foreach ($p in $Path)
{
$shell = new-object -Comobject shell.application
$fileName = $p
$zip = $shell.namespace("$filename")
$Results += $zip.items()| where-object { $_.Name -like "*C*" -or $_.Name -like
"*b*" }
}
foreach($item in $Results )
{
$shell.namespace($dest).copyhere($item)
}
© 2022 - 2024 — McMap. All rights reserved.