Native UnZip using COM?

Started by airr, May 31, 2024, 04:37:05 PM

Previous topic - Next topic

airr

Give it a try and let me know your results....src$ and dest$ need to be full paths, I cheated and just put the zip file in the same directory as the code/exe and created the Macro so I don't have to type out the full paths by hand.  ;D



MACRO DirName$ = replace$(command$(0),appexename$,"")

Dim As Object objShell, objZip
Dim src$, dest$


src$ = DirName$ + "Bcx809.zip"
dest$ = DirName$

set objShell = COM("Shell.Application")

Set objZip = objShell.NameSpace(src$).Items

objShell.NameSpace(dest$).CopyHere objZip, 16

print "DONE."

Set objZip = Nothing
Set objShell = Nothing




AIR.

airr

Crap, could have used AppExePath$ instead of the macro, but either way......

AIR.

MrBcx

That worked great ... another short and sweet solution!

Here is a BED friendly version with only a few minor changes.



Dim As Object objShell, objZip
Dim src$, dest$

src$ = Appexepath$ + "Bcx809.zip"
dest$ = Appexepath$

Comset objShell = Com("Shell.Application")

Comset objZip = objShell.NameSpace(src$).Items

objShell.NameSpace(dest$).CopyHere objZip, 16

If Exist(Appexepath$ + "\Bcx809") Then
    Print src$, " was unzipped!"
Else
    Print "Something went wrong"
End If

Comset objZip = Nothing
Comset objShell = Nothing


airr

Here is how to zip a file/folder:



Function main(argc as integer, argv as pchar ptr)

    CreateZip(AppExePath$ + "TEST.zip", AppExePath$ + "Bcx809" )

End Function


Sub CreateZip(zipFile$, sourcePath$)
    dim header$*22

    sprint header, "PK", Chr$(5), Chr$(6), String$(18,0)

    open zipFile$ for binary new as zFile
        put$ zFile, header, 22
    close zFile

    AddToZip(zipFile$, sourcePath$)

End Sub

Sub AddToZip(zipFile$, sourcePath$)
    Dim As Object objShell, objSource, objTarget

    Comset objShell = COM("Shell.Application")
    Comset objTarget = objShell.NameSpace(zipFile$)
    Comset objSource = objShell.NameSpace(sourcePath$).Items

    if isobject(objTarget) and isobject(objSource) then
        objTarget.CopyHere objSource, 20
    end if

    UNCOM(objSource)
    UNCOM(objTarget)
    UNCOM(objShell)

End Sub



AIR.

Vortex

Hi airr,

Thanks for your last code. I can build the application. Creating a zip file, the application is crashing. The zip file has no any problems. Operating system : Windows 7 Sp1 64-bit

Same crashing issue with Kevin's code :

https://bcxbasiccoders.com/smf/index.php?topic=1068.msg5535#msg5535

MrBcx

#5
IMO, although interesting, neither of these should be used for anything serious.

I tested the unzip code on several zip files and all unzipped correctly.

The zip code (create a new zip) is pretty flaky in my tests. 

It seems to work best on folders with very few files in it and no sub folders.
It hasn't crashed, per se, but many times it only creates a zip file 22 bytes in size
I found where these techniques were being tinkered with by VB coders 10+ years ago.

Maybe there is more to the story?


I'm running Windows 10 Pro 22H2