Results 1 to 24 of 24

Thread: [RESOLVED] Extract a .zip file

  1. #1

    Thread Starter
    Fanatic Member Emcrank's Avatar
    Join Date
    Jan 2009
    Posts
    566

    Resolved [RESOLVED] Extract a .zip file

    How can i extract all the files from a .zip file into a directory? I have to do this because no free file hosting allows .exe files so im going to have my program download the .zip file containing the .exe then extract that file when its downloaded.

  2. #2
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Extract a .zip file

    You can do it directly with VB.NET, but I generally prefer not to. I think you have to look up ZipSharLib, or something like that. It's an external dependency that allows you to incorporate zipping.

    I always prefer to use 7za, which is a command line zip utility that you can package with you app and then just send the appropriate arguments to zip or unzip files I've used it extensively with one of my apps.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  3. #3

  4. #4
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Extract a .zip file

    Quote Originally Posted by Emcrank View Post
    Would it mean having to have something else in the app directory? How would i do it directly?
    Yes. You'd have to include the app with your application.

    That's generally preferred. I wouldn't know how to use the library I mentioned, since I've never used it.

    Though the first place to start would be the documentation and Google. I still find your quote to be ironic, given the amount of research put into the questions... well, rather the lack thereof
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  5. #5

    Thread Starter
    Fanatic Member Emcrank's Avatar
    Join Date
    Jan 2009
    Posts
    566

    Re: Extract a .zip file

    I have searched google and visited many sites but they all include downloading something and putting it in your app's folder. I really want to avoid this. Ill try the documentation now.

  6. #6
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Extract a .zip file

    Quote Originally Posted by Emcrank View Post
    I have searched google and visited many sites but they all include downloading something and putting it in your app's folder. I really want to avoid this. Ill try the documentation now.
    Even with the SharpZipLib, you'll have to include its dependencies, which are most likely .DLLs. And in those cases, when the app is installed, they will be saved on the user's PC.

    At the very least, you can include the 7za as a resource and write it to a temp location, unzip the files, then delete it.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  7. #7

  8. #8
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Extract a .zip file

    Quote Originally Posted by Emcrank View Post
    could you show me an example how to unzip and zip 7za? Thankyou
    You should really remove the quote from your signature. It's philosophy that is great in nature, but only valid when executed. It does not represent your actions thus far.

    It took me some time and a lot of testing to figure out how to use 7za properly with VB. I wouldn't want to deprive you of that learning experiencing.

    When I wanted to learn how to use 7za, I did this and found this.

    Once you figure out how to use it, it's relatively simple with Process.Start. Just define a variable as a new process, assign the StartInfo.Arguments, StartInfo.WorkingDirectory, .StartInfo.FileName and the call start on your previously defined variable.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  9. #9

    Thread Starter
    Fanatic Member Emcrank's Avatar
    Join Date
    Jan 2009
    Posts
    566

    Re: Extract a .zip file

    Oh is the 7za way like some Shell ways i found on google?? I want to try and keep it in Vb as much as i can like just have a class and subs in that class then call the subs and pass arguments to the subs. Do you understand me? Any other unzipper thing you can suggest what would allow me to do this?

  10. #10
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Extract a .zip file

    7za is a command line utility. It's your best option.

    The only other way I know of is to include a zip library made for VB. The only library I'm awre of is ZipSharLib. However, like I mentioned before, I've never used it.

    Why don't you want to include 7za? I've seen a lot of applications, personal and commercial, that use a 3rd party app like 7za for purposes such as these. There's no shame in it =/
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  11. #11

    Thread Starter
    Fanatic Member Emcrank's Avatar
    Join Date
    Jan 2009
    Posts
    566

    Re: Extract a .zip file

    Its just i hate it when i have exra things in the directory than the executable, is there any documentation on MSDN about the built in way?
    Ill try the documentation now.
    I couldn't find anything i dont know how to navigate that site properly could you post a link or something to it. It would be much appreciated, also where can i download this ZipSharLib?? I will try that if i cannot figure out the built in way. Thankyou in advance.

  12. #12
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Extract a .zip file

    is there any documentation on MSDN about the built in way?
    There is no built in way. I never said there was. I only mentioned there was a way of doing it with VB.NET via SharpZipLib. But that's a 3rd party library that can be included in .NET applications. You can find more information at their website, located here. Please Google the things I'm telling you. If you had Googled ZipSharpLib, you would have obtained at least some general information about it.

    You're not helping me help you. If you're not willing to do the research, then just stop. We're all willing to help, but we will lose interest if you're not showing us that you're trying.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  13. #13

    Thread Starter
    Fanatic Member Emcrank's Avatar
    Join Date
    Jan 2009
    Posts
    566

    Re: Extract a .zip file

    Sorry i have been trying i just havn't shown it i did find some DLL's which were meant to let you manage .zip files earlier but they didn't work. Also when i try download ZipSharp it says page cannot be found, Do you have a copy? or know anywhere else to get one? Look this is the website to download it from(i think) and the 2 links at side dont work. http://www.carto.ca/

  14. #14

  15. #15
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: Extract a .zip file

    Quote Originally Posted by Emcrank View Post
    Ok i found a website to download it from: http://www.brothersoft.com/sharpzipl...oad-27636.html Can you check that this is the correct one your talking about.
    That looks fine, but you can download it directly, from here.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  16. #16
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Extract a .zip file

    Why not use the built-in unzipping utility of windows? You can reference Shell32.dll then try the following codes. They are in C# but it can be easily converted.
    Code:
    private void ExtractZip(string zipFile, string destination)
    {
        Shell32.Shell shell = new Shell32.Shell();
        shell.NameSpace(destination).CopyHere(shell.NameSpace(zipFile).Items(), null);
        shell = null;
        MessageBox.Show("Done");
    }
    
    private void button1_Click(object sender, EventArgs e)
    {
        ExtractZip(@"C:\PIS\ENUMWINDOWS.zip", @"C:\PIS\Test\");
    }
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  17. #17

    Thread Starter
    Fanatic Member Emcrank's Avatar
    Join Date
    Jan 2009
    Posts
    566

    Re: Extract a .zip file

    Where can i find the Shell32.dll to reference to - What folder is it in?
    Also how can i create a zip file?

  18. #18

    Thread Starter
    Fanatic Member Emcrank's Avatar
    Join Date
    Jan 2009
    Posts
    566

    Re: Extract a .zip file

    VB.NET Code:
    1. Private Sub ExtractZip(zipFile As  String, destination As String)
    2.           Dim shell As New Shell32.Shell()
    3.           shell.[NameSpace](destination).CopyHere(shell.[NameSpace](zipFile).Items(), Nothing)
    4.           shell = Nothing
    5.           MessageBox.Show("Done")
    6. End Sub
    7.  
    8. Private Sub button1_Click(sender As Object, e As EventArgs)
    9.           ExtractZip("C:\PIS\ENUMWINDOWS.zip", "C:\PIS\Test\")
    10. End Sub
    ok i tried to convert it, is that correct??

  19. #19
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Extract a .zip file

    Shell32.dll is usually located in C:\Windows\System32\. Did you try running it if it is successful? Here's another translation in case yours does not work.

    Code:
    Private Sub ExtractZip(ByVal zipFile As String, ByVal destination As String)
            Dim shell As Shell32.Shell = New Shell32.Shell
            shell.NameSpace(destination).CopyHere(shell.NameSpace(zipFile).Items, Nothing)
            shell = Nothing
            MessageBox.Show("Done")
        End Sub
        
        Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
            ExtractZip("C:\PIS\ENUMWINDOWS.zip", "C:\PIS\Test\")
        End Sub
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  20. #20

  21. #21
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Extract a .zip file

    This is my VB6.0 code to create a zip file, you can convert it to VB.Net, they look similar. And this uses late-binding, you can just use early-binding.
    Code:
    Public Sub ZipFile(ByVal strFileToZip, ByVal strTargetZip)
        CreateEmptyZip strTargetZip
    
        CreateObject("Shell.Application").Namespace(strTargetZip).CopyHere strFileToZip
    End Sub
    
    Private Sub CreateEmptyZip(ByVal sPath As String)
        Dim strZIPHeader As String
    
        strZIPHeader = Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String$(18, 0) ' header required to convince Windows shell that this is really a zip file
        CreateObject("Scripting.FileSystemObject").CreateTextFile(sPath).Write strZIPHeader
            
    End Sub
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  22. #22
    Frenzied Member MaximilianMayrhofer's Avatar
    Join Date
    Aug 2007
    Location
    IM IN YR LOOP
    Posts
    2,001

    Re: Extract a .zip file

    I have done shell invoking as shown here, but found that it seems to run incredibly slowly, even for small files.

  23. #23

  24. #24
    Frenzied Member
    Join Date
    Jul 2006
    Location
    MI
    Posts
    2,012

    Re: Extract a .zip file

    Try this ... it works great.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width