I'm trying to use SharpZipLib to pull specified files from a zip archive. All of the examples I've seen always expect that you want to unzip the entire zip, and do something along the lines of:
FileStream fileStreamIn = new FileStream (sourcePath, FileMode.Open, FileAccess.Read);
ZipInputStream zipInStream = new ZipInputStream(fileStreamIn);
ZipEntry entry;
while (entry = zipInStream.GetNextEntry() != null)
{
// Unzip file
}
What I want to do is something like:
ZipEntry entry = zipInStream.SeekToFile("FileName");
As my needs involve using a zip as a package and only grabbing files into memory as needed.
Is anyone familiar with SharpZipLib? Does anyone know if I can do this without running through the entire zip by hand?
can extract one or more files based on a file filter (ie regular expressoin string)
Here's the doc regarding the file filter:
so for a file named myfile.dat you could use "+.*myfile\.dat$" as your file filter.
ZipFile.GetEntry should do the trick:
I get an option to VB.NET, to extract specific files from Zip archivers. Comments in Spanish. Take a Zip file path, Filename you want extracted, password if needed. Extract to original path if OriginalPath is setted to 1, or use DestPath if OriginalPath=0. Keep an eye in "ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputStream" stuff...
It's as follows:
DotNetZip has a string indexer on the ZipFile class to make this really easy.
You don't need to fiddle with inputstreams and outputstreams and so on, just to extract a file. On the other hand if you want the stream, you can get it:
You can also do wildcard extractions.
There are overloads to specify overwrite/no-overwrite, different target directories, etc. You can also extract based on criteria other than the filename. For example, extract all files newer than January 15, 2009:
And you can combine criteria:
You don't have to extract the files that you select. You can just select them and then make decisions on whether to extract or not.