Solved

Unzip a package(with sub-folders)

Posted on 2004-04-27
9
549 Views
Last Modified: 2011-10-03
Hello,

I have the folllowing function in VB.NET using icsharp

Function Unzip(ByVal zipFile As String, ByVal UnzipToFolder As String)

        Dim nByte As Integer
        Dim s As New ICSharpCode.SharpZipLib.Zip.ZipInputStream(System.IO.File.OpenRead(zipFile))
        Dim entry As ICSharpCode.SharpZipLib.Zip.ZipEntry
        Dim Zip_Data(2048) As Byte
        Zip_Data(2048) = New Byte

        entry = s.GetNextEntry

        Do

            Dim fs As New System.IO.FileStream(System.IO.Path.Combine(UnzipToFolder, System.IO.Path.GetFileName(entry.Name)), System.IO.FileMode.Create)

            Dim bw As New System.IO.BinaryWriter(fs, System.Text.Encoding.ASCII)

            nByte = s.Read(Zip_Data, 0, Zip_Data.GetLength(0))

            While nByte > 0
                bw.Write(Zip_Data, 0, nByte)
                nByte = s.Read(Zip_Data, 0, Zip_Data.GetLength(0))
            End While

            fs.Close()
            bw.Close()
            entry = s.GetNextEntry

        Loop While Not (entry Is Nothing)

        s.Close()

    End Function

The problem with this function is that it crasehes when i have subfolders in the  zipped package. Why is that? and more importantly, HOW DO I FIX IT???
0
Comment
Question by:b_o_b
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
9 Comments
 
LVL 5

Expert Comment

by:chaniewskim
ID: 10931700
Check the IsDirectory attribute on your zip entry, and skip this entry or create corresponding directory if it is true.
0
 
LVL 5

Expert Comment

by:chaniewskim
ID: 10931715
Sorry, my english can be sometimes confusing.

Check the IsDirectory attribute on your zip entry, and if it is true, then skip this entry or create corresponding directory.

0
 

Author Comment

by:b_o_b
ID: 10931732
ok, I understand how to use the isdirectory and check the entry, but if it returns true, how do I create a corresponding directory?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:chaniewskim
ID: 10931796
You can use a function Directory.CreateDirectory (path As String)
0
 
LVL 5

Expert Comment

by:chaniewskim
ID: 10931810
ex.


Directory.CreateDirectory ( System.IO.Path.Combine(UnzipToFolder, System.IO.Path.GetFileName(entry.Name)) )
0
 

Author Comment

by:b_o_b
ID: 10932015
Still not working, im getting filez unzipped, but not in the correct structure, all the files are getting unzipped in the main folders and I dont see any subfolders getting created
This is what i tried

The structure of the package is as followed

2 folders(Compenent and Scripts)
4 files
          Folder Component (1 folder(sql) and 10 files)
                      Folder Sql (1 file)
          Folder Scripts (11 folders and 30 files)
                      Folder (each of the 11 folders have 3 files)

The unzip process must keep the same structure

Here is the redone function

 Function unzip2(ByVal zipFile As String, ByVal UnzipToFolder As String)
        Dim nByte As Integer
        Dim s As New Zip.ZipInputStream(System.IO.File.OpenRead(zipFile))
        Dim entry As Zip.ZipEntry
        Dim Zip_Data(2048) As Byte
        Zip_Data(2048) = New Byte

        entry = s.GetNextEntry

        Do

            If entry.IsDirectory Then
                System.IO.Directory.CreateDirectory(System.IO.Path.Combine(UnzipToFolder, System.IO.Path.GetFileName(entry.Name)))
            Else
                Dim fs As New System.IO.FileStream(System.IO.Path.Combine(UnzipToFolder, System.IO.Path.GetFileName(entry.Name)), System.IO.FileMode.Create)

                Dim bw As New System.IO.BinaryWriter(fs, System.Text.Encoding.ASCII)

                nByte = s.Read(Zip_Data, 0, Zip_Data.GetLength(0))

                While nByte > 0
                    bw.Write(Zip_Data, 0, nByte)
                    nByte = s.Read(Zip_Data, 0, Zip_Data.GetLength(0))
                End While

                fs.Close()
                bw.Close()
            End If
            entry = s.GetNextEntry


        Loop While Not (entry Is Nothing)

        s.Close()


    End Function
 
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 250 total points
ID: 11176992
It sounds like you want a recursive function, but I don't see any other call to unzip2.

Bob
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.net and sql server 4 54
VB.Net - MemoryMappedFiles - Confirm receipt 2 36
ModalPopup  question 22 38
Stop Git from being my repository 1 23
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question