This project is read-only.

ExtractSelectedEntries with powershell

Jul 15, 2011 at 3:18 PM
Edited Jul 15, 2011 at 3:38 PM

I was trying to use ExtractSelectedEntries in powershell. Simpliest try was something like this

$zipfile = [Ionic.Zip.ZipFile]::Read($sourceFile)             
$zipfile.ExtractSelectedEntries("name=*", "\a\b\c", "c:\output")

But it just returned NameCriterion regexString(^.*$) and nothing was extracted.
What was I doing wrong here?

Jul 15, 2011 at 3:40 PM

I already did this one on my own.
Correct criteria for ArchiveFolder is without leading \. That is

$zipfile.ExtractSelectedEntries("name=*", "a\b\c", "c:\output")
Jul 15, 2011 at 3:57 PM

But I got into another problem. Given example extracts just files in \a\b\c archive folder, but no subfolders.
How could I extract all subfolders (recusively) for given archive folder?

Jul 15, 2011 at 7:12 PM

Dragan, I believe you want something like "a\b\c\*\*.*"


Jul 15, 2011 at 9:21 PM

I tried it like this.

$zipfile.ExtractSelectedEntries("name=*", "a\b\c\*\*.*", "c:\output")

but this extracted  just nothing at all.

What I need is to extract one folder from the zip file, but with all files and subfolders recursively.
Is there one liner for it, or should I write the function that does tree walk and?


Jul 16, 2011 at 1:18 AM

I'm sorry, I wasn't paying attention.  I meant that you should try, as your criteria string, 'name=a\b\c\*\*.*'


Jul 16, 2011 at 8:10 PM

I tried
$zipfile.ExtractSelectedEntries('name=a\b\c\*\*.*', 'a\b\c', "e:\users\dragan\DotNetZip\output")
but it extracts nothing.

Note that
$zipfile.ExtractSelectedEntries('name=a\b\c\*\*.*', 'a\b\c', "e:\users\dragan\DotNetZip\output")
at least does extract files from folder a\b\c, but it does not extract subfolder a\b\c\d

More ideas?



Jul 18, 2011 at 8:59 AM

I tried just simple


It works perfectly. But what I need is to define output folder, therefore I need  ExtractSelectedEntries(String, String, String).
I was trying to use $null for second parameter eg.

$zipfile.ExtractSelectedEntries('name=a\b\c\*', $null, "e:\users\dragan\DotNetZip\output")

but this extracts nothing.




Jul 19, 2011 at 2:17 PM

Try using the empty string, instead of null, for that 2nd parameter.  eg, ""

Jul 19, 2011 at 3:16 PM

I was trying this already, but it did not work.

I did workaround. I set directory for writing with [System.IO.Directory]::SetCurrentDirectory, than use ExtractSelectedEntries with just one parameter.
I have working solution now, but if better solution occures I would be still interested in it.

thanks for response