|
-
Jul 10th, 2023, 04:09 PM
#1
Thread Starter
Member
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?
-
Jul 10th, 2023, 04:16 PM
#2
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
-
Jul 11th, 2023, 09:32 AM
#3
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.
-
Jul 11th, 2023, 11:27 AM
#4
Thread Starter
Member
Re: VB6 extract files from a winzip created zip file.
-
Jul 11th, 2023, 11:28 AM
#5
Thread Starter
Member
Re: VB6 extract files from a winzip created zip file.
Please a little bit more help VB6 code of course. Thank you
-
Jul 11th, 2023, 11:30 AM
#6
Thread Starter
Member
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.
-
Jul 11th, 2023, 11:42 AM
#7
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.
Last edited by wqweto; Jul 11th, 2023 at 11:45 AM.
-
Jul 11th, 2023, 12:37 PM
#8
Thread Starter
Member
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
-
Jul 11th, 2023, 04:19 PM
#9
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
-
Jul 11th, 2023, 04:33 PM
#10
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.
-
Aug 24th, 2024, 10:49 AM
#11
Thread Starter
Member
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.
-
Aug 24th, 2024, 10:53 AM
#12
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.
-
Aug 24th, 2024, 11:43 AM
#13
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>
-
Aug 25th, 2024, 12:27 PM
#14
Thread Starter
Member
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.
-
Aug 28th, 2024, 06:21 PM
#15
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
-
Aug 29th, 2024, 02:26 AM
#16
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|