When does extract execute?

Aug 18, 2009 at 10:24 PM

if you loop through a zip file and extract each file in the zip, does the extraction of the file from the zip occur in each call to extract or at the end?  If not how can I get each file to exist?

as in the example below.

Dim ZipToUnpack As String = "C1P3SML.zip" 
   Dim TargetDir As String = "C1P3SML" 
   Console.WriteLine("Extracting file {0} to {1}", ZipToUnpack, TargetDir)  
   Using zip1 As ZipFile = ZipFile.Read(ZipToUnpack)  
       AddHandler zip1.ExtractProgress, AddressOf MyExtractProgress  
       Dim e As ZipEntry  
       ' here, we extract every entry, but we could extract   
       ' based on entry name, size, date, etc.  
       For Each e In zip1  
           e.Extract(TargetDir, ExtractExistingFileAction.OverwriteSilently)  

' does each file exist at this point

       Next 
   End Using 

Coordinator
Aug 18, 2009 at 10:29 PM
Edited Aug 18, 2009 at 10:29 PM

Norton, you keep using different signin names?

The file will exist immediately after the call to e.Extract() returns. 

Aug 18, 2009 at 11:15 PM

I was using the Extract(String, ExtractExistingFileAction) overload and found that extract was extracting to the base directory(string) and then adding in the ZIP folder pathing to place the file further down the base directory. In Winzip to solve this problem I uncheck the “Use Folder name” and Winzip places in the unzipped file in the base directory. What can I do to get the files in the zip only in the base directory with no ZIP folder names?

Thanks

Colby

**********************************************************************
This communication does not reflect an intention by the sender or the 
sender's client or principal to conduct a transaction or make any 
agreement by electronic means.  Nothing contained within either this 
message or any attachment shall satisfy the requirements for a writing, 
and nothing contained herein shall constitute a contract or electronic 
signature under the Electronic Signatures in Global and National 
Commerce Act (ESIGN), any version of the Uniform Electronic Transactions
Act (UETA), or any other statute governing electronic transactions. This
electronic transmission and any attached documents or other writings are
confidential and for the sole use of the intended recipient(s) identified
above.  This message may contain information that is privileged, 
confidential, or otherwise protected from disclosure under applicable law.  
If you are not the intended recipient, or employee, or agent responsible 
for delivering the information to the intended recipient, you are hereby 
notified that any use, reading, dissemination, distribution, copying, or 
storage of this information is strictly prohibited.
If you have received this information in error, please notify Town North 
Bank via e-mail at IntrusionDetection@tnbonline.com and delete the 
electronic transmission, including all attachments from your system.
**********************************************************************
Coordinator
Aug 19, 2009 at 12:37 AM
Edited Aug 19, 2009 at 1:00 AM

For now, you have to reset the name of the entry, conditionally, like this:

  Using zip1 As ZipFile = ZipFile.Read(ZipPath)
      For Each e As ZipEntry In zip1
          If e.FileName.Contains("/") Then
              Dim s As String = System.IO.Path.GetFileName(e.FileName)
              Dim n As Integer = 0
              Do While Not (zip1(s) Is Nothing)
                  n = n+1
                  s = System.IO.Path.GetFileNameWithoutExtension(e.FileName) & "." & n.ToString() & _
                      System.IO.Path.GetExtension(e.FileName) 
              Loop
              e.FileName = s
          End If
          e.Extract(extractPath, ExtractExistingFileAction.OverwriteSilently)
      Next
  End Using

This code ensures that any entries that share a base name with other entries in the ZipFile, are extracted with unique names.

There's an open workitem (7803) requesting that this capability be built-in.

Coordinator
Aug 19, 2009 at 2:41 AM

ok, I just released v1.8.4.19. With that release there's a new property on the ZipFile class to make this simpler. It's called FlattenFoldersOnExtract. Use it like this:

Using zip1 As ZipFile = ZipFile.Read(ZipPath)
    zip1.FlattenFoldersOnExtract = True
    For Each e As ZipEntry In zip1
        e.Extract(extractPath, ExtractExistingFileAction.OverwriteSilently)
    Next
End Using

or this:

Using zip1 As ZipFile = ZipFile.Read(ZipPath)
    zip1.FlattenFoldersOnExtract = True
    zip1.ExtractAll(extractPath, ExtractExistingFileAction.OverwriteSilently)
End Using

 

Aug 20, 2009 at 4:01 PM

Thanks for your help. Downloaded the new release and it worked.

**********************************************************************
This communication does not reflect an intention by the sender or the 
sender's client or principal to conduct a transaction or make any 
agreement by electronic means.  Nothing contained within either this 
message or any attachment shall satisfy the requirements for a writing, 
and nothing contained herein shall constitute a contract or electronic 
signature under the Electronic Signatures in Global and National 
Commerce Act (ESIGN), any version of the Uniform Electronic Transactions
Act (UETA), or any other statute governing electronic transactions. This
electronic transmission and any attached documents or other writings are
confidential and for the sole use of the intended recipient(s) identified
above.  This message may contain information that is privileged, 
confidential, or otherwise protected from disclosure under applicable law.  
If you are not the intended recipient, or employee, or agent responsible 
for delivering the information to the intended recipient, you are hereby 
notified that any use, reading, dissemination, distribution, copying, or 
storage of this information is strictly prohibited.
If you have received this information in error, please notify Town North 
Bank via e-mail at IntrusionDetection@tnbonline.com and delete the 
electronic transmission, including all attachments from your system.
**********************************************************************
Coordinator
Aug 20, 2009 at 4:06 PM

great, glad it worked for you.