[
  {
    "Id": "198800",
    "ThreadId": "58717",
    "Html": "<p>Hello all.</p>\r\n<p>First off, great library, I love it.<br>My problem is this:</p>\r\n<p>Say I have an archive with a file in it like this: /foldera/folderb/file.txt</p>\r\n<p>I would like to extract &quot;file.txt&quot; to C:\\folderc\\file.txt - but when I use ZipFile.Extract(&quot;/foldera/folderb/file.txt&quot;,&quot;C:\\folderc&quot;) I obviously end up wit: C:\\folderc\\foldera\\folderb\\file.txt</p>\r\n<p>How does one &quot;leave off&quot; the relative path and just extract the single file to a directory?</p>\r\n<p>Thank you,<br>Backslash</p>",
    "PostedDate": "2009-06-07T13:51:07.427-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "198808",
    "ThreadId": "58717",
    "Html": "<p>What's your language?&nbsp; In vb.net,&nbsp;you can do what you want with code&nbsp;like this:</p>\r\n<pre>Dim Overwrite as ExtractExistingFileAction = ExtractExistingFileAction.OverwriteSilently\r\nUsing zip1 As ZipFile = ZipFile.Read(ZipToUnpack)\r\n  Dim e As ZipEntry \r\n  For Each e In zip1\r\n    ' change the name of the ZipEntry in memory, to remove the path\r\n    e.FileName = System.IO.Path.GetFileName(e.FileName)\r\n    ' extract that entry, with the modified name, into the specified directory\r\n    e.Extract(&quot;C:\\folderc&quot;, Overwrite)\r\n  Next \r\nEnd Using \r\n\r\n</pre>\r\n<p>There was a request to add a new method to make this simpler. &nbsp;(<a href=\"http://dotnetzip.codeplex.com/WorkItem/View.aspx?WorkItemId=7803\">http://dotnetzip.codeplex.com/WorkItem/View.aspx?WorkItemId=7803</a>) &nbsp;Because the way you do this today&nbsp;is so simple, and because it is a rare enough case, I am not sure if a new method&nbsp;in the DotNetZip interface&nbsp;is necessary.</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2009-06-07T14:23:23.26-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "198831",
    "ThreadId": "58717",
    "Html": "<p>I'm working in C# but I can see what you're doing. It even makes sense in it's own right. Thanks for that, and thanks for the quick answer. I'll give it a try when I get home.</p>\r\n<p>:)</p>",
    "PostedDate": "2009-06-07T16:27:08.967-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "198840",
    "ThreadId": "58717",
    "Html": "<p>No problem. In C# it looks like this:</p>\r\n<pre>var overwrite = ExtractExistingFileAction.OverwriteSilently;\r\nusing (var zip1 = ZipFile.Read(ZipToUnpack))\r\n{\r\n  foreach (var e in zip1)\r\n  {\r\n    // change the name of the ZipEntry in memory, to remove the path\r\n    e.FileName = System.IO.Path.GetFileName(e.FileName);\r\n    // extract that entry, with the modified name, into the specified directory\r\n    e.Extract(&quot;C:\\\\folderc&quot;, overwrite);\r\n  }\r\n}\r\n</pre>\r\n<p>Or, if you want to extract just one, or a few particular entries, maybe something like this:</p>\r\n<pre>using (var zip1 = ZipFile.Read(ZipToUnpack))\r\n{\r\n  var e = zip1[&quot;\\\\folderA\\\\folderB\\\\entryName.txt&quot;];\r\n  // change the name of the ZipEntry in memory, to remove the path\r\n  e.FileName = System.IO.Path.GetFileName(e.FileName);\r\n  // extract that entry, with the modified name, into the specified directory\r\n  e.Extract(&quot;C:\\\\folderc&quot;, overwrite);\r\n}\r\n</pre>\r\n<p>When you call ZipFile.Read(), you create an in-memory representation of the zip file. That representation includes a list of all the entries from the zip file, and each entry includes a path. What you are doing by setting the FileName property of one of the particular entries is just modifying the in-memory representation of the zip file.&nbsp; Then you extract the entry, using that modified pathname.&nbsp; Easy.</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2009-06-07T17:31:03.963-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "218505",
    "ThreadId": "58717",
    "Html": "<p>I'm having some trouble with the code from the second post in VB2008 (under Windows 7 (don't know if that's important)).</p>\r\n<p>The line &quot;e.FileName = System.IO.Path.GetFileName(e.FileName)&quot; generates the following error: &quot;ZipException was unhandled&quot;, &quot;The filename must be non-empty and non-null.&quot;</p>\r\n<p>When I put &quot;Debug.Print(System.IO.Path.GetFileName(e.FileName))&quot; in the for-loop I indeed get blank lines in between the filenames.</p>\r\n<p>All help welcomed.</p>\r\n<pre><br></pre>\r\n<p>&nbsp;</p>",
    "PostedDate": "2009-08-02T12:26:21.807-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "218508",
    "ThreadId": "58717",
    "Html": "<p>The Windows 7 part is not important.</p>\r\n<p>what are you trying to do?&nbsp; are you trying to strip paths from the entries in a zip file?</p>\r\n<p>You could be having this exception if you set e.FileName to Nothing. Could this be possible? How?</p>\r\n<p>What is the value of Path.GetFileName() if there is no slash in the argument? I'm not sure. It could be Nothing. But you can test this out pretty easily.</p>\r\n<p>I don't know exactly what you mean by &quot;get blank lines&quot;. Maybe you need to insert a condition on the assignment.</p>\r\n<pre>  If e.FileName.Contains(&quot;/&quot;) Then\r\n    e.FileName = Path.GetFileName(e.FileName)\r\n  End If\r\n</pre>\r\n<p>or</p>\r\n<pre>  If Not Path.GetFileName(e.FileName) Is Nothing Then\r\n    e.FileName = Path.GetFileName(e.FileName)\r\n  End If\r\n</pre>\r\n<p>(not sure of the VB syntax, but I think that's right)</p>",
    "PostedDate": "2009-08-02T12:40:03.96-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "218954",
    "ThreadId": "58717",
    "Html": "<p>Ok, part of the issue is solved.</p>\r\n<p>I'm now using the following code</p>\r\n<p>Using zip1 As ZipFile = ZipFile.Read(ZipPath)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim Overwrite As ExtractExistingFileAction = ExtractExistingFileAction.OverwriteSilently<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim e As ZipEntry<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim tester As String<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For Each e In zip1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If System.IO.Path.GetFileName(e.FileName) &lt;&gt; &quot;&quot; Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e.FileName = System.IO.Path.GetFileName(e.FileName)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e.Extract(FullInstallPath, Overwrite)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next<br>End Using</p>\r\n<p>If the zip-file has the following files it works (files A,B and C all end up in the folder FullInstallPath, as intended):</p>\r\n<p>submapA/FileC.txt<br>FileA.txt<br>FileB.txt</p>\r\n<p>&nbsp;</p>\r\n<p>However, zip-files like the following where some files need to be overwritten, generate an error on the 'Next'-line</p>\r\n<p>submapA/FileA.txt<br>FileA.txt<br>FileB.txt</p>\r\n<p>The Error states: Collection was modified; enumeration operation may not execute.</p>\r\n<p>I hope this info is helpful to you. Thanks for DotNetZip and for your help so far.</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2009-08-03T14:17:41.31-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "218956",
    "ThreadId": "58717",
    "Html": "<p>ok, there are two things going on here.</p>\r\n<p>First, is the strange error you get from DotNetZip &quot;Collection was modified.&quot;&nbsp; That shouldn't happen.&nbsp; I'll fix that.</p>\r\n<p>Second, you have a conflict - there are two files that you want to extract, into the same place.&nbsp;&nbsp;&nbsp;In your second example &quot;submapA/FileA.txt&quot; and &quot;FileA.txt&quot; will both get the FileName &quot;FileA.txt&quot;.&nbsp; You will have to decide what you want to do in that case, to resolve the conflict.&nbsp;</p>\r\n<p>&nbsp;</p>",
    "PostedDate": "2009-08-03T14:23:39.673-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "218965",
    "ThreadId": "58717",
    "Html": "<p>ok, now when you try to rename an entry to a name that already exists in the archive, instead of the cryptic &quot;Collection was modified&quot; exception, you will get a more&nbsp;clear and helpful error:</p>\r\n<pre>extracting the modified zip....\r\nException: Ionic.Zip.ZipException: Cannot rename fodder/next/FileA.zzz to FileA.zzz; an entry by that name already exists in the archive.\r\n   at Ionic.Zip.ZipEntry.set_FileName(String value) in c:\\dinoch\\dev\\dotnet\\zip\\DotNetZip\\Zip Partial DLL\\ZipEntry.cs:line 831\r\n   at Ionic.Tests.Something.dusteagle.Run() in c:\\dinoch\\dev\\dotnet\\zip\\test\\dusteagle.vb:line 87\r\n   at Ionic.Tests.Something.dusteagle.Main(String[] args) in c:\\dinoch\\dev\\dotnet\\zip\\test\\dusteagle.vb:line 136\r\n</pre>\r\n<p>This will be in the next binary release of the library.</p>\r\n<p>You still have to decide what you want to do in the case of duplicates.</p>",
    "PostedDate": "2009-08-03T14:51:48.673-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "219171",
    "ThreadId": "58717",
    "Html": "<p>Thanks, I understand the problem better now. You can not have two identical filenames in a single zipfile. I thought ExtractExistingFileAction.OverwriteSilently took care, but that is only for files already existing in the target directory.</p>\r\n<p>Is there a way to retain the largest one of both submapA/FileA.txt and FileA.txt and extract only that one?</p>",
    "PostedDate": "2009-08-04T03:17:21.327-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "219200",
    "ThreadId": "58717",
    "Html": "<p>Yes, you cannot have two entries with the same name, in a zip file.</p>\r\n<p>And Yes, the way to retain the largest one is to scan through and get the largest one.&nbsp; You could do this with a loop, or a LIINQ query over the entries.</p>\r\n<div style=\"color:Black;background-color:White\">\r\n<pre><div style=\"color:Black;background-color:White\"><pre><span style=\"color:Blue\">Using</span> zip <span style=\"color:Blue\">As</span> ZipFile = ZipFile.Read(ZipPath)\r\n    <span style=\"color:Blue\">Dim</span> g2 = _\r\n        <span style=\"color:Blue\">From</span> e <span style=\"color:Blue\">in</span> zip _\r\n        <span style=\"color:Blue\">Group</span> e <span style=\"color:Blue\">by</span> Name = System.IO.Path.GetFileName(e.FileName) <span style=\"color:Blue\">Into</span> <span style=\"color:Blue\">Group</span>\r\n\r\n    <span style=\"color:Blue\">For</span> <span style=\"color:Blue\">Each</span> elt <span style=\"color:Blue\">in</span> g2\r\n        <span style=\"color:Blue\">Dim</span> x = elt\r\n        <span style=\"color:Blue\">Dim</span> largest = (<span style=\"color:Blue\">From</span> e <span style=\"color:Blue\">In</span> x.<span style=\"color:Blue\">Group</span> _\r\n                       <span style=\"color:Blue\">Where</span> e.UncompressedSize = x.<span style=\"color:Blue\">Group</span>.<span style=\"color:Blue\">Max</span>(<span style=\"color:Blue\">Function</span>(entry) entry.UncompressedSize) _\r\n                       <span style=\"color:Blue\">Select</span> e) _\r\n            .First\r\n        Console.WriteLine(<span style=\"color:#A31515\">&quot;    {1,8}  {0}&quot;</span>, largest.FileName, largest.UncompressedSize)\r\n\r\n         <span style=\"color:Blue\">If</span> (largest.UncompressedSize &gt; 0) <span style=\"color:Blue\">Then</span>\r\n             largest.FileName = elt.Name\r\n             largest.Extract(<span style=\"color:#A31515\">&quot;queryzip&quot;</span>)\r\n         <span style=\"color:Blue\">End</span> <span style=\"color:Blue\">If</span>\r\n     <span style=\"color:Blue\">Next</span>\r\n<span style=\"color:Blue\">End</span> <span style=\"color:Blue\">Using</span>\r\n\r\n</pre>\r\n</div>\r\n</pre>\r\n</div>",
    "PostedDate": "2009-08-04T04:47:10.583-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  },
  {
    "Id": "221294",
    "ThreadId": "58717",
    "Html": "<p>Thanks for your help. I've worked around it by loading all info into an array and first renaming the files I don't want to unzip and then stripping the relative paths.</p>",
    "PostedDate": "2009-08-09T11:41:18.27-07:00",
    "UserRole": null,
    "MarkedAsAnswerDate": null
  }
]