Results 1 to 16 of 16

Thread: VB6 extract files from a winzip created zip file.

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2013
    Posts
    32

    VB6 extract files from a winzip created zip file.

    Using code that I found here at VBForums I am trying to extract a zip file.
    The posting says that all I have to do is include cZipArchive.cls in the project.
    I downloaded and included the file as a class module.
    The form is one button with the following code.

    Private Sub Command1_Click
    With New cZipArchive '<----- Module is Not a valid type.
    .OpenArchive App.Path & "\test.zip"
    .Extract "C:\Path\To\extract_folder"
    End With
    end sub

    I ended up including mdGlobals.bas as a module.

    Could someone please explain what I am doing wrong, please?

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: VB6 extract files from a winzip created zip file.

    Modules are by definition a static class, and so cannot be instanciated ... also not sure what including mdglobals.bas has to do with anything.
    Outside of that, without knowing what code you used or where from (VBForums is a big place with a long and rich history)... hard to say much more.


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    Hyperactive Member -Franky-'s Avatar
    Join Date
    Dec 2022
    Location
    Bremen Germany
    Posts
    476

    Re: VB6 extract files from a winzip created zip file.

    I assume that cZipArchive.cls from wqweto is meant. For example, you can also unpack ZIPs using SHFileOperation with FO_COPY.

  4. #4

    Thread Starter
    Member
    Join Date
    Apr 2013
    Posts
    32

    Re: VB6 extract files from a winzip created zip file.

    I believe that I found code here:

    https://www.vbforums.com/showthread....ip-File-in-VB6

  5. #5

    Thread Starter
    Member
    Join Date
    Apr 2013
    Posts
    32

    Re: VB6 extract files from a winzip created zip file.

    Please a little bit more help VB6 code of course. Thank you

  6. #6

    Thread Starter
    Member
    Join Date
    Apr 2013
    Posts
    32

    Re: VB6 extract files from a winzip created zip file.

    All I am trying to do is silently unzip a couple of zip files into a sub-directory that I name.

    There are a lot of examples here. However I cannot seem to get anything to work. I am building a program for disabled people.
    Last edited by wjkssmd; Jul 11th, 2023 at 11:58 AM.

  7. #7
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    6,167

    Re: VB6 extract files from a winzip created zip file.

    Go to original ZipArchive repo's releases and download latest Source code (zip) link.

    Extract the ZIP with sources and add cZipArchive.cls from src sub-folder to your project. It's a class module (ends with .cls), not a standard module (which end with .bas).

    After this "fix" sample code you found on the interwebs should start working immediately.

    cheers,
    </wqw>

    p.s. This is VB6 forum and ZipArchive is a VB6 project so it will *not* work in VBA if you plan on using it there.

  8. #8

    Thread Starter
    Member
    Join Date
    Apr 2013
    Posts
    32

    Re: VB6 extract files from a winzip created zip file.

    OMG.... it works.... it all had to do with not having latest version... I was banging my head big time. I owe you one if I can ever repay you.

    I made up the following code to extract my zip file.

    Option Explicit

    Private Sub Command1_Click()
    Dim oUnzip As cZipArchive
    Set oUnzip = New cZipArchive

    oUnzip.OpenArchive ("C:\PhraseBook\Test\Alphabet.zip")
    oUnzip.Extract ("C:\PhraseBook\Test")

    If oUnzip.Extract <> 0 Then
    MsgBox oUnzip.LastError
    End If

    Set oUnzip = Nothing

    End Sub

  9. #9
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

    Re: VB6 extract files from a winzip created zip file.

    Basic unzip without 3rd party DLL or shell32- IStorage-based-VBForums
    https://www.vbforums.com/showthread....IStorage-based

    you also can try this,about 150 lines code

  10. #10
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

    Re: VB6 extract files from a winzip created zip file.

    10 lines code:
    Code:
    Private Declare Function MakeSureDirectoryPathExists Lib "imagehlp" (ByVal PathName As String) As Long
    Function UnzipFile(PathToZip As String, ByVal PathToDest As String) As Boolean
    On Error Resume Next
    If Dir(PathToZip) = "" Then Exit Function
    PathToDest = Replace(PathToDest, "/", "\")
    If Right(PathToDest, 1) <> "\" Then PathToDest = PathToDest & "\"
    MakeSureDirectoryPathExists PathToDest
    With CreateObject("Shell.Application") 'Crazy work around
        .NameSpace("" & PathToDest).CopyHere .NameSpace("" & PathToZip).Items, 20
    End With
    UnzipFile = Err.Number = 0
    End Function
    Last edited by xiaoyao; Jul 11th, 2023 at 05:10 PM.

  11. #11

    Thread Starter
    Member
    Join Date
    Apr 2013
    Posts
    32

    Re: VB6 extract files from a winzip created zip file.

    Is there a way that I can overwrite the files when unzipping.
    I find that a file included in the zip is not being extracted when the surrounding files exist.
    To be more precise... I have approx 100 jpg files in a zip. I want to avoid mass deleting all of the files in the directory in case the user has created something. I just want to add the one file to the subdirectory and skip the other files.

    I was thinking of creating a temp directory to unzip the file into and then checking one by one for existence. If not found copy the file from the temp directory into the user's program directory.

    Thanks for your interest.
    Last edited by wjkssmd; Aug 24th, 2024 at 10:53 AM.

  12. #12
    PowerPoster VanGoghGaming's Avatar
    Join Date
    Jan 2020
    Location
    Eve Online - Mining, Missions & Market Trading!
    Posts
    2,622

    Talking Re: VB6 extract files from a winzip created zip file.

    The default behavior should be to overwrite existing files. I am surprised this hasn't been implemented but it shouldn't be difficult to locate the procedure that saves files and change it to overwrite existing files.

  13. #13
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    6,167

    Re: VB6 extract files from a winzip created zip file.

    > The default behavior should be to overwrite existing files.

    Yes, indeed. This *is* the default behavior but overwriting files can be customized using BeforeExtract event like this:

    Code:
    Option Explicit
    
    Private WithEvents m_oZip As cZipArchive
    
    Private Sub Form_Load()
        Set m_oZip = New cZipArchive
        With m_oZip
            .OpenArchive "D:\TEMP\aaa.zip"
            .Extract "D:\TEMP\ExtractTest"
        End With
    End Sub
    
    Private Function FileExists(ByVal sFile As String) As Boolean
        FileExists = (LenB(Dir$(sFile)) <> 0)
    End Function
    
    Private Sub m_oZip_BeforeExtract(ByVal FileIdx As Long, File As Variant, SkipFile As Boolean, Cancel As Boolean)
        SkipFile = FileExists(File)
    End Sub
    This customizes the extractor behavior to literally skip any file which exists in target folder.

    Can be fine-tuned to skip only newer files too.

    cheers,
    </wqw>

  14. #14

    Thread Starter
    Member
    Join Date
    Apr 2013
    Posts
    32

    Re: VB6 extract files from a winzip created zip file.

    Thank you for the input...

    My problem was that I added New JPG files to a subdirectory within the zip file. The extract was not finding the new files and they were skipped.

    This procedure worked for me. This means that I don't have to delete subdirectorys of JPG files just to then unzip all the files to update them.

    That was so much easier than what I was thinking of doing.

    It even gets to the newly added files in sub sub directories.
    Last edited by wjkssmd; Aug 25th, 2024 at 12:58 PM.

  15. #15
    PowerPoster
    Join Date
    Jan 2020
    Posts
    5,538

    Re: VB6 extract files from a winzip created zip file.

    Private Function FileExists(ByVal sFile As String) As Boolean
    FileExists = (LenB(Dir$(sFile)) <> 0)
    End Function

    you can get zip file list(a.jpg,b.jpg,c.jpg),get new filesize and updatetime
    for check file in disk path:d:\unziptest\a.jpg
    if filesize or updatetime not same,so it's a new file or update file

  16. #16
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    6,167

    Re: VB6 extract files from a winzip created zip file.

    You can also set File parameter in event to different filename so the file is not overwritten but still created. You can ask user what to do by showing some UI in the event.

Tags for this Thread

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