Results 1 to 9 of 9

Thread: Zip and Unzip Compressing

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2008
    Location
    Argentina
    Posts
    440

    Zip and Unzip Compressing

    Hello people anyone knows any dll to compress and decompress such as those listed here? at least with those I do not get what I want, I do not see the option to list files or directories not investigate much but apparently this complicated decompress keeping the tree compressed directory is decompressed say everything in one folder without creating subfolders they can be compressed.

    usually I use Shell.Application but I would like to find another alternative.
    leandroascierto.com Visual Basic 6 projects

  2. #2
    gibra
    Guest

    Re: Zip and Unzip Compressing


  3. #3
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,653

    Re: Zip and Unzip Compressing

    For basic zip/unzip, I ported a unique way of doing it through the shell without the need for any DLL depends, just my TLB for shell programming:
    [VB6] Basic unzip without 3rd party DLL or shell32- IStorage-based, and
    [VB6] Create a ZIP file without any DLL depends using IStorage and IDropTarget - Uses IStorage and IStream for basic zip functionality. Creating a Zip uses a neat trick with IDropTarget.

    Not sure what you were saying about the directory tree, but both of these methods preserve the existing folder structure, although the code could be altered to disregard it.

    Edit: If you want to show the contents of an existing zip, you can very quickly just throw up an Explorer frame using interfaces from the same TLB,
    Code:
    Private pEB As ExplorerBrowser
    
    Private Sub NavigateZip(pObj As IShellItem)
    'pObj here would be the psiResult IShellItem from .GetResult in the code
    'for picking a zip with pOpenDlg. Just make it public and don't destroy it
    If (pEB Is Nothing) Then
        Set pEB = New ExplorerBrowser
        Dim prc As oleexp3.RECT
        Dim pfs As FOLDERSETTINGS
        
        pfs.fFlags = FWF_ALIGNLEFT
        pfs.ViewMode = FVM_DETAILS
        prc.Top = 15
        prc.Bottom = (Frame1.Height / 15) - 5
        prc.Left = 5
        prc.Right = (Frame1.Width / 15) - 5
        
        pEB.Initialize Frame1.hWnd, prc, pfs
        pEB.SetOptions EBO_NONE
    End If
    
    pEB.BrowseToObject pObj, 0&
    
    End Sub

    All the navigation and icons/details are all automatic. As a bonus, since it's a full featured Explorer frame, you can even drag/drop with the contents to extract/add specific items without any additional code.
    Last edited by fafalone; Jun 19th, 2016 at 03:59 PM.

  4. #4
    Frenzied Member
    Join Date
    Dec 2008
    Location
    Melbourne Australia
    Posts
    1,487

    Re: Zip and Unzip Compressing

    I am not fully grasping what you said in your OP (Original Post)
    But if your need is the ability to programmatically easily zip and unzip, then I recommend this -
    http://www.codeguru.com/vb/gen/vb_gr...VB5-or-VB6.htm
    I use it.
    You do not have to register the DLLs, just place them in the same folder as your EXE

    HTH,
    Rob

  5. #5
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Zip and Unzip Compressing

    If you read it slowly and carefuly enough applying your strongest text-speak filters to extract a glimmer of meaning, then follow his link... he already says these don't do what he wants.

    But I suppose there is a chance that the demo wrapper project you linked to might help him. Without copy/paste code a lot of VB users are completely helpless.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2008
    Location
    Argentina
    Posts
    440

    Re: Zip and Unzip Compressing

    Hey guys thanks for your time. @Gibra the link I provide me, uses the same dll that mentioned in the initial post. one of the problem with this DLL ,is that not list the files.

    @Falalone interesting .tlb, but it is the same problem with Shell.Application, I try to decompress a file, but not a .zip extension.
    for example a file excel.xlsm is a compressed zip file (You can check this by changing the extension of .xlsm to .zip) but you can not explore using Shell Interface. The only way is to rename the file to .zip
    I would like to explain in detail some cons, but the language limits me a lot (Spanish)
    leandroascierto.com Visual Basic 6 projects

  7. #7
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,653

    Re: Zip and Unzip Compressing

    EDIT: So I looked into the .XLSM format, and it does appear to be a zip but the treatment of it is controlled by the file extension.

    Is there any reason you couldn't rename, extract, then restore original name? If you rename it to .zip, the method in my unzip post can extract it (and the IExplorerBrowser can navigate it--- that it doesn't without the rename confirms there's nothing inherently unreadable).

    Edit2: Really simple-
    Code:
    Private Sub Command2_Click()
    If Right$(sZipFile, 4) = "xlsm" Then
        Name sZipFile As sZipFile & ".zip"
        sZipFile = sZipFile & ".zip"
        UnzipFile sZipFile
        'and name back right after
        sZipFile = Left$(sZipFile, Len(sZipFile) - 4)
        Name sZipFile & ".zip" As sZipFile
    Else
        UnzipFile sZipFile
    End If
    End Sub
    Confirmed working on Win7 x64. You could do basically the same trick to list the files/folders too; rename, SHCreateItemFromParsingName, browse.. here's the code altered to handle both browsing, extracting, and renaming back to the original when done, from GetResult in Command1:
    Code:
        .GetResult psiRes
        psiRes.GetDisplayName SIGDN_FILESYSPATH, lpName
        sZipFile = LPWSTRtoStr(lpName)
        Text1.Text = sZipFile
        If Right$(sZipFile, 4) = "xlsm" Then
            sHold = sZipFile
            sZipFile = (Left$(sZipFile, Len(sZipFile) - 4) & ".zip")
            Name sHold As sZipFile
            bRename = True 'flag to rename later.
            SHCreateItemFromParsingName StrPtr(sZipFile), ByVal 0&, IID_IShellItem, psiRes
        End If
        
        NavigateZip psiRes
    
    'then:
    Private Sub Command2_Click()
    
    UnzipFile sZipFile
    
    If bRename = True Then
        pEB.Destroy
        Name sZipFile As sHold
        bRename = False
    End If
    End Sub
    (with sHold declared as Private sHold As String, and bRename Private bRename As Boolean)
    ..it really is determined exclusively by extension. I tried a whole bunch of different ways of obtaining the IStorage interface, but they all absolutely refuse to work without a .zip extension. Windows will absolutely not, under any circumstance, process a zip file that isn't named .zip.


    Edit again:
    As far as determining IF an arbitrary file is actually a ZIP, since there's no definitive list of extensions, your choices are just list the extensions you know, or actually open the file and check for the signature; first four bytes = \x50\x4b\x03\x04
    You can do a hard check on any file system file like this:
    Code:
    'this api is in the unzip sample but in case:
    Public Declare Function SHCreateStreamOnFileEx Lib "shlwapi" (ByVal pszFile As Long, ByVal grfMode As STGM, ByVal dwAttributes As FILE_ATTRIBUTES, ByVal fCreate As Long, ByVal pstmTemplate As Long, ppstm As oleexp3.IStream) As Long
    'all other consts/ifaces are in the tlb
    
    Public Function IsZipFile(sFile As String) As Boolean
    On Error GoTo done
    Dim aBytes() As Byte
    Dim pStrm As oleexp3.IStream
    Dim hr As Long
    
    hr = SHCreateStreamOnFileEx(StrPtr(sFile), STGM_READ, FILE_ATTRIBUTE_NORMAL, 0&, 0&, pStrm)
    
    ReDim aBytes(3) 'valid ZIP file is 0x50,0x4B,0x03,0x04
    pStrm.Read aBytes(0), 4
    If (aBytes(0) = &H50) And (aBytes(1) = &H4B) And (aBytes(2) = &H3) And (aBytes(3) = &H4) Then
        'an empty zip file would be 0x50,0x4B,0x05,0x06; adjust if you want to count that as valid 
        IsZipFile = True
    End If
    
    done:
    Set pStrm = Nothing
    
    End Function
    Last edited by fafalone; Jun 20th, 2016 at 05:35 AM.

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2008
    Location
    Argentina
    Posts
    440

    Re: Zip and Unzip Compressing

    thank you very much, finally i opted for your module, is much faster than PLS use Shell.Application object.
    leandroascierto.com Visual Basic 6 projects

  9. #9
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,653

    Re: Zip and Unzip Compressing

    Just wanted to note that checking the first 4 bytes to see if an arbitrary file is actually a Zip isn't nearly the performance hit I thought it would be. Had to set up an ultra high resolution timer to get an exact number: that function executes in 0.05-0.18ms. And I don't even have a high performance HD; just a regular 7200rpm SATA consumer class drive. So it's ok to use no matter how many files you're checking (a basic function just checking if the extension was .zip executed in 0.03ms, so barely any difference).
    Last edited by fafalone; Jun 23rd, 2016 at 01:35 AM.

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