?
Solved

Unzip a package(with sub-folders)

Posted on 2004-04-27
9
Medium Priority
?
553 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 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month11 days, 5 hours left to enroll

770 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