[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Unzip a package(with sub-folders)

Posted on 2004-04-27
9
Medium Priority
?
554 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
Technology Partners: 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 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

650 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