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
Solved

Unzip a package(with sub-folders)

Posted on 2004-04-27
9
548 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
  • 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VS.net 2010 11 48
Get the selected ValueMember of Combobox 5 38
Calculate number of nights between two dates 5 53
Iteration Help (Asp.net VB) 5 24
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

792 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