Extract zip file to directory

Apr 19, 2010 at 9:07 AM

I'm using VB.net 2008 with DotNetZip-v1.9.

I'm extracting files that only contain one entry. When they are extracted a sub directory in created and they are placed in it.

I do not want a sub directory created but for the file to be extracted directly to the root folder containing the zip.

Here is what I tried and errors that I received:


TheFile is a System.IO.FileInfo

Using ThisZIP As ZipFile = ZipFile.Read(TheFile.FullName)

For Each ThisEntry As ZipEntry In ThisZIP.Entries

ThisEntry.FileName = System.IO.Path.GetFileName(ThisEntry.FileName)

ThisEntry.Extract("E:\DataTemp\", ExtractExistingFileAction.DoNotOverwrite) 


 End Using

The file is extracted properly in the correct directory but I then get an exception thrown:

"Collection was modified; enumeration operation may not execute."

2)Since there is only one entry in my zips I would prefer to just use ExtractAll, but I can not get it to extract to the root folder of the zip.

Dim ExtractedFullName As String = TheFile.FullName.Remove(TheFile.FullName.Length - 4) & ".xml"

Using ThisZIP As New ZipFile(TheFile.FullName)


End Using

3) This was an example I found on a discussion but the ExtractAll() gives a error if I don't add a parameter to it.
Using zip As ZipFile.Read(FilePath)

zip.StatusMessageTextWriter= System.Console.Out

'Status Messages will be sent to the console during extraction


End Using

4)This is what I'm using now. It works but I don't like it.

Using ThisZIP As ZipFile = ZipFile.Read(TheFile.FullName)

ThisZIP.Entries(0).FileName = System.IO.Path.GetFileName(ThisZIP.Entries(0).FileName)

ThisZIP.Entries(0).Extract("E:\DataTemp\", ExtractExistingFileAction.DoNotOverwrite)

End Using

If you have any suggestions, I appreciate it. I have spent some time searching thru the other discussions but have not found the answer I thought I needed.



Apr 21, 2010 at 4:16 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.