我现在利用ZIP32.DLL已经可以对指定文件进行压缩,但是无法对目录进行整体压缩,即
e:\123
|---a.doc
|---b.ini
|---c.txt
|---subDir    (子目录)
     |---d.doc
     |---e.txt
这是一个举例,现在我可以实现压缩a,b,c3个文件,但是无法压缩subDir下的d和e两个文件,有没有办法对e:\123目录整个进行压缩呢,包括子目录的压缩,可以吗?

解决方案 »

  1.   

    参考:
    http://www.vbaccelerator.com/home/VB/Code/Libraries/Compression/Zipping_Files/VB6_Zip_Sample_Project.asp
    以及
    http://www.vbaccelerator.com/home/VB/Code/Libraries/Compression/Zipping_Files/VB6_Zip_Sample_Project_zip_mZip_bas.asp
      

  2.   

    汗,我无法打开网页,TechnoFantasy(冰儿马甲www.applevb.com)你能把例子发给我吗?或者是把这个网页另存为发给我可以吗?
    [email protected]
    非常感谢
      

  3.   

    我down了这个例子,但是它也是只允许你同时压缩几个文件,而不是一个目录下的所有文件和子目录,我现在想实现的效果就是当我们用鼠标右击某个目录并选择"Add to 123.zip"的时候的效果啊,它会自动把123这个目录下的所有东西包括子目录下的所有文件都进行压缩打包的,这种效果怎么实现呢?
      

  4.   

    zip32.dll就是安装winzip后有的啊,一般在windows\system32下吧
      

  5.   

    TO flying_ylh (一平) 
    想问一下,用ZIP32.DLL压缩文件是怎么操作的,能否给我一个实例呀/不胜感谢[email protected]
      

  6.   

    '将一下代码保存在模块中:
    Option Explicit
    '****************************************************
    '欢迎访问小聪明的主页VB版: http://coolzm.533.net
    '****************************************************
    '---------------------------------------------------
    ' Sample VB 5 code to drive zip32.dll
    ' Contributed to the Info-Zip project by Mike Le Voi
    '
    ' Contact me at: [email protected]
    '
    ' Visit my home page at: http://modemss.brisnet.org.au/~mlevoi
    '
    ' Use this code at your own risk. Nothing implied or warranted
    ' to work on your machine :-)
    '---------------------------------------------------'argv
    Public Type ZIPnames
        s(0 To 99) As String
    End Type'ZPOPT is used to set options in the zip32.dll
    Private Type ZPOPT
        fSuffix As Long
        fEncrypt As Long
        fSystem As Long
        fVolume As Long
        fExtra As Long
        fNoDirEntries As Long
        fExcludeDate As Long
        fIncludeDate As Long
        fVerbose As Long
        fQuiet As Long
        fCRLF_LF As Long
        fLF_CRLF As Long
        fJunkDir As Long
        fRecurse As Long
        fGrow As Long
        fForce As Long
        fMove As Long
        fDeleteEntries As Long
        fUpdate As Long
        fFreshen As Long
        fJunkSFX As Long
        fLatestTime As Long
        fComment As Long
        fOffsets As Long
        fPrivilege As Long
        fEncryption As Long
        fRepair As Long
        flevel As Byte
        date As String ' 8 bytes long
        szRootDir As String ' up to 256 bytes long
    End TypePrivate Type ZIPUSERFUNCTIONS
        DLLPrnt As Long
        DLLPASSWORD As Long
        DLLCOMMENT As Long
        DLLSERVICE As Long
    End Type'Structure ZCL - not used by VB
    'Private Type ZCL
    '    argc As Long            'number of files
    '    filename As String      'Name of the Zip file
    '    fileArray As ZIPnames   'The array of filenames
    'End Type' Call back "string" (sic)
    Private Type CBChar
        ch(4096) As Byte
    End Type'Local declares
    Dim MYOPT As ZPOPT
    ' Dim MYZCL As ZCL
    Dim MYUSER As ZIPUSERFUNCTIONS'This assumes zip32.dll is in your \windows\system directory!
    Private Declare Function ZpInit Lib "zip32.dll" _
    (ByRef Zipfun As ZIPUSERFUNCTIONS) As Long ' Set Zip CallbacksPrivate Declare Function ZpSetOptions Lib "zip32.dll" _
    (ByRef Opts As ZPOPT) As Long ' Set Zip optionsPrivate Declare Function ZpGetOptions Lib "zip32.dll" _
    () As ZPOPT ' used to check encryption flag onlyPrivate Declare Function ZpArchive Lib "zip32.dll" _
    (ByVal argc As Long, ByVal funame As String, ByRef argv As ZIPnames) As Long ' Real zipping actionGlobal vbzipinf As String, crlf$' Puts a function pointer in a structure
    Function FnPtr(ByVal lp As Long) As Long
        FnPtr = lp
    End Function' Callback for zip32.dll
    Function DLLPrnt(ByRef fname As CBChar, ByVal x As Long) As Long
        Dim s0$, xx As Long    ' always put this in callback routines!
        On Error Resume Next
        s0 = ""
        For xx = 0 To x
            If fname.ch(xx) = 0 Then xx = 99999 Else s0 = s0 + Chr(fname.ch(xx))
        Next xx
        ' vbzipinf = vbzipinf + s0
        'Form1.Print s0;
        DoEvents
        DLLPrnt = 0
    End Function' Callback for zip32.dll
    Function DllPass(ByRef s1 As Byte, x As Long, _
        ByRef s2 As Byte, _
        ByRef s3 As Byte) As Long    ' always put this in callback routines!
        On Error Resume Next
        ' not supported - always return 1
        DllPass = 1
    End Function' Callback for zip32.dll
    Function DllComm(ByRef s1 As CBChar) As CBChar
        
        ' always put this in callback routines!
        On Error Resume Next
        ' not supported always return \0
        s1.ch(0) = vbNullString
        DllComm = s1
    End Function'Main Subroutine
    Function VBZip(argc As Integer, zipname As String, _
            mynames As ZIPnames, junk As Integer, _
            recurse As Integer, updat As Integer, _
            freshen As Integer, basename As String) As Long
        
        Dim hmem As Long, xx As Integer
        Dim retcode As Long
        
        On Error Resume Next ' nothing will go wrong :-)
        
        ' Set address of callback functions
        MYUSER.DLLPrnt = FnPtr(AddressOf DLLPrnt)
        MYUSER.DLLPASSWORD = FnPtr(AddressOf DllPass)
        MYUSER.DLLCOMMENT = FnPtr(AddressOf DllComm)
        MYUSER.DLLSERVICE = 0& ' not coded yet :-)
        retcode = ZpInit(MYUSER)
        
        ' Set zip options
        MYOPT.fSuffix = 0        ' include suffixes (not yet implemented)
        MYOPT.fEncrypt = 0       ' 1 if encryption wanted
        MYOPT.fSystem = 0        ' 1 to include system/hidden files
        MYOPT.fVolume = 0        ' 1 if storing volume label
        MYOPT.fExtra = 0         ' 1 if including extra attributes
        MYOPT.fNoDirEntries = 0  ' 1 if ignoring directory entries
        MYOPT.fExcludeDate = 0   ' 1 if excluding files earlier than a specified date
        MYOPT.fIncludeDate = 0   ' 1 if including files earlier than a specified date
        MYOPT.fVerbose = 0       ' 1 if full messages wanted
        MYOPT.fQuiet = 0         ' 1 if minimum messages wanted
        MYOPT.fCRLF_LF = 0       ' 1 if translate CR/LF to LF
        MYOPT.fLF_CRLF = 0       ' 1 if translate LF to CR/LF
        MYOPT.fJunkDir = junk    ' 1 if junking directory names
        MYOPT.fRecurse = recurse ' 1 if recursing into subdirectories
        MYOPT.fGrow = 0          ' 1 if allow appending to zip file
        MYOPT.fForce = 0         ' 1 if making entries using DOS names
        MYOPT.fMove = 0          ' 1 if deleting files added or updated
        MYOPT.fDeleteEntries = 0 ' 1 if files passed have to be deleted
        MYOPT.fUpdate = updat    ' 1 if updating zip file--overwrite only if newer
        MYOPT.fFreshen = freshen ' 1 if freshening zip file--overwrite only
        MYOPT.fJunkSFX = 0       ' 1 if junking sfx prefix
        MYOPT.fLatestTime = 0    ' 1 if setting zip file time to time of latest file in archive
        MYOPT.fComment = 0       ' 1 if putting comment in zip file
        MYOPT.fOffsets = 0       ' 1 if updating archive offsets for sfx Files
        MYOPT.fPrivilege = 0     ' 1 if not saving privelages
        MYOPT.fEncryption = 0    'Read only property!
        MYOPT.fRepair = 0        ' 1=> fix archive, 2=> try harder to fix
        MYOPT.flevel = 0         ' compression level - should be 0!!!
        MYOPT.date = vbNullString ' "12/31/79"? US Date?
        MYOPT.szRootDir = basename
        
        ' Set options
        retcode = ZpSetOptions(MYOPT)
        
        ' ZCL not needed in VB
        ' MYZCL.argc = 2
        ' MYZCL.filename = "c:\wiz\new.zip"
        ' MYZCL.fileArray = MYNAMES
        
        ' Go for it!
        retcode = ZpArchive(argc, zipname, mynames)
        
        VBZip = retcode
    End Function
      

  7.   

    '调用压缩
            Dim argc As Integer, zipname As String
            Dim mynames As ZIPnames, basename As String
            Dim rc As Integer, junk As Integer
            Dim recurse As Integer, updat As Integer, freshen As Integer
            
            Cls
            
            ' Set options - only the common ones are shown here
            junk = 0    ' 1=throw away path names
            recurse = 0 ' 1=recurse -R 2=recurse -r 2=most useful :)
            updat = 0   ' 1=update only if newer
            freshen = 0 ' 1=freshen - overwrite only
            
            ' Select some files - wildcards are supported
            argc = 2   ' number of elements of mynames array
            zipname = 要保存的zip文件名
            mynames.s(0) = 要压缩的文件
            mynames.s(1) = 要压缩的文件"
            basename = 保存的目录 ' this affects the stored path name
            
            ' Go for it!
            rc = VBZip(argc, zipname, mynames, junk, recurse, _
                updat, freshen, basename)
      

  8.   

    利用SHELL调用WINZIP是可以实现压缩子目录的,但是我不想受控于SHELL,想通过调用DLL来实现该功能,不知道可以吗