DotNetZip: How to extract files, but ignoring the path in the zipfile?

Kumar picture Kumar · Mar 9, 2010 · Viewed 22.4k times · Source

Trying to extract files to a given folder ignoring the path in the zipfile but there doesn't seem to be a way.

This seems a fairly basic requirement given all the other good stuff implemented in there.

What am i missing ?

code is -

using (Ionic.Zip.ZipFile zf = Ionic.Zip.ZipFile.Read(zipPath))
{
    zf.ExtractAll(appPath);
}

Answer

Andrew Timson picture Andrew Timson · Feb 20, 2012

While you can't specify it for a specific call to Extract() or ExtractAll(), the ZipFile class has a FlattenFoldersOnExtract field. When set to true, it flattens all the extracted files into one folder:

var flattenFoldersOnExtract = zip.FlattenFoldersOnExtract;
zip.FlattenFoldersOnExtract = true;
zip.ExtractAll();
zip.FlattenFoldersOnExtract = flattenFoldersOnExtract;