[VB] UNZIP32 (ZIP32J+ZIP32) ・・・・・(ZIPの圧縮・解凍・アーカイバ処理)


  UNZIP.bas




  

' ******************************************************
' UNZIP32
' 圧縮には ZIP32J.DLL+ZIP32.DLL要
' ******************************************************
Type INDIVIDUALINFO
    dwOriginalSize As Long
    dwCompressedSize As Long
    dwCRC As Long
    uFlag As Integer
    uOSType As Integer
    wDate0 As Integer
    wTime0 As Integer
    wRatio As Integer
    wDate As Integer
    wTime As Integer
    szFileName As String * 513
    dummy1 As String * 3
    szAttribute As String * 8
    szMode As String * 8
    dummy2 As String * 512
End Type

' ------------------------------------------------------
' バージョン情報
' ------------------------------------------------------
Declare Function UnZipGetVersion Lib "unzip32.dll" () As Integer

' ------------------------------------------------------
' 書庫ファイルOPEN
' ------------------------------------------------------
Declare Function UnZipOpenArchive Lib "unzip32.dll" ( _
    ByVal hWnd As Long, _
    ByVal szFileName As String, _
    ByVal dwMode As Long _
) As Long

' ------------------------------------------------------
' 書庫ファイルCLOSE
' ------------------------------------------------------
Declare Function UnZipCloseArchive Lib "unzip32.dll" ( _
    ByVal harc As Long _
) As Integer

' ------------------------------------------------------
' 初回検索
' ------------------------------------------------------
Declare Function UnZipFindFirst Lib "unzip32.dll" ( _
    ByVal harc As Long, _
    ByVal szWildName As String, _
    lpSubInfo As INDIVIDUALINFO _
) As Integer

' ------------------------------------------------------
' 2回目以降の検索
' ------------------------------------------------------
Declare Function UnZipFindNext Lib "unzip32.dll" ( _
ByVal harc As Long, _
lpSubInfo As INDIVIDUALINFO _
) As Integer

' ------------------------------------------------------
' 解凍
' ------------------------------------------------------
Declare Function UnZip Lib "unzip32.dll" ( _
    ByVal hWnd As Long, _
    ByVal szCmdLine As String, _
    ByVal szOutput As String, _
    ByVal dwSize As Long _
) As Integer

' ------------------------------------------------------
' 圧縮
' ------------------------------------------------------
Declare Function Zip Lib "zip32j.dll" ( _
    ByVal hWnd As Long, _
    ByVal szCmdLine As String, _
    ByVal szOutput As String, _
    ByVal dwSize As Long _
) As Integer


Type FILETIME
        dwLowDateTime As Long
        dwHighDateTime As Long
End Type
Type SYSTEMTIME
        wYear As Integer
        wMonth As Integer
        wDayOfWeek As Integer
        wDay As Integer
        wHour As Integer
        wMinute As Integer
        wSecond As Integer
        wMilliseconds As Integer
End Type
Declare Function FileTimeToSystemTime Lib "kernel32" ( _
    lpFileTime As FILETIME, _
    lpSystemTime As SYSTEMTIME _
) As Long
Declare Function DosDateTimeToFileTime Lib "kernel32" ( _
    ByVal wFatDate As Long, _
    ByVal wFatTime As Long, _
    lpFileTime As FILETIME _
) As Long

Global harc As Variant

' ******************************************************
' アーカイブを開く
' ******************************************************
Public Function OpenZip(hWnd As Long, strPath As String)

    Dim ret As Long

    If TypeName(harc) <> "Empty" Then
        Call UnZipCloseArchive(harc)
        harc = Empty
    End If
    
    ret = UnZipOpenArchive(hWnd, strPath, 2)
    harc = ret

End Function

' ******************************************************
' アーカイブを閉じる
' ******************************************************
Public Function CloseZip()

    If TypeName(harc) <> "Empty" Then
        Call UnZipCloseArchive(harc)
        harc = Empty
    End If

End Function

' ******************************************************
' アーカイブを読む
' ******************************************************
Public Function FindZip(strTarget, ByRef UnzipData As INDIVIDUALINFO) As Long

    If strTarget <> "" Then
        FindZip = UnZipFindFirst(harc, strTarget, UnzipData)
    Else
        FindZip = UnZipFindNext(harc, UnzipData)
    End If

End Function

' ******************************************************
' ディレクトリ圧縮
' ******************************************************
Public Function ZipFreezeDir(hWnd As Long, strTargetDir, strTargetZip) As Long

    Dim strCommand As String
    Dim strOut As String * 512
    Dim nSize As Long
    
    strCommand = "-ur " & strTargetZip & " " & strTargetDir & "\*"
    nSize = 512
    ZipFreezeDir = Zip(hWnd, strCommand, strOut, nSize)

End Function

' ******************************************************
' レスポンスファイルによる圧縮
' ******************************************************
Public Function ZipFreeze(hWnd As Long, strTargetDir, strTargetList, strTargetZip) As Long

    Dim strCommand As String
    Dim strOut As String * 512
    Dim nSize As Long
    
    strCommand = "-u " & strTargetZip & " " & strTargetDir & "\ @" & strTargetList
    nSize = 512
    ZipFreeze = Zip(hWnd, strCommand, strOut, nSize)

End Function

' ******************************************************
' 書庫解凍
' ******************************************************
Public Function ZipMelt( _
    hWnd As Long, _
    strOption, _
    strTargetZip, _
    strTargetDir, _
    strFileSpec _
) As Long

    Dim strCommand As String
    Dim strOut As String * 512
    Dim nSize As Long
    
    strCommand = strOption & " """ & strTargetZip & """ " & strTargetDir & "\ " & strFileSpec
    nSize = 512
    ZipMelt = UnZip(hWnd, strCommand, strOut, nSize)

End Function

' ******************************************************
' バイナリの日付を文字列に変換
' ******************************************************
Public Function GetDosDateTime(wDate As Integer, wTime As Integer) As String
    
    Dim lpFileTime As FILETIME
    Dim lpSystemTime As SYSTEMTIME

    Call DosDateTimeToFileTime(wDate, wTime, lpFileTime)
    Call FileTimeToSystemTime(lpFileTime, lpSystemTime)
    
    GetDosDateTime = _
        Format(lpSystemTime.wYear, "0000") & "/" & _
        Format(lpSystemTime.wMonth, "00") & "/" & _
        Format(lpSystemTime.wDay, "00") & " " & _
        Format(lpSystemTime.wHour, "00") & ":" & _
        Format(lpSystemTime.wMinute, "00") & ":" & _
        Format(lpSystemTime.wSecond, "00")

End Function

  







  アーカイバ処理サンプル




  

Private Sub Command1_Click()

    Dim sts As Long
    Dim uData As INDIVIDUALINFO
    Dim bFirst As Boolean

    Grid.Clear
    Grid.Rows = 2

    Call OpenZip(Me.hWnd, "アーカイブファイルのパス")
    bFirst = True
    
    Do
    
        If bFirst Then
            bFirst = False
            sts = FindZip("*.*", uData)
            If sts <> 0 Then
                Exit Do
            End If
        Else
            sts = FindZip("", uData)
            If sts <> 0 Then
                Exit Do
            End If
            Grid.Rows = Grid.Rows + 1
        End If

        With Grid

            .TextMatrix(.Rows - 1, 0) = .Rows - 1
            .TextMatrix(.Rows - 1, 1) = uData.szFileName
            .TextMatrix(.Rows - 1, 2) = GetDosDateTime(uData.wDate, uData.wTime)
            .TextMatrix(.Rows - 1, 3) = Format(uData.dwOriginalSize, "#,##0")
            .TextMatrix(.Rows - 1, 4) = Format(uData.dwCompressedSize, "#,##0")
            If uData.dwOriginalSize = 0 Then
                .TextMatrix(.Rows - 1, 5) = 0
            Else
                .TextMatrix(.Rows - 1, 5) = _
                    Format((uData.dwCompressedSize / uData.dwOriginalSize) * 100, "#0")
            End If
            .TextMatrix(.Rows - 1, 6) = uData.szAttribute
            .TextMatrix(.Rows - 1, 7) = uData.szMode
            
        End With

    Loop

    Call CloseZip

End Sub

Private Sub Form_Load()
    
    With Grid
    
        .Cols = 8
        .ColWidth(0) = 400
        .ColWidth(1) = 3000
        .ColWidth(2) = 1700
        .ColWidth(5) = 500
        .ColWidth(6) = 600
        .ColWidth(7) = 600
    
    End With

End Sub

  

  圧縮・解凍サンプル

  

Private Sub Command2_Click()

    Call ZipFreezeDir(Me.hWnd, "d:\temp", "zipのパス")

End Sub
Private Sub Command3_Click()

    Call ZipMelt(Me.hWnd, "-x -s -C -o", "zipのパス", "D:\temp\zipmelt", "*.*")

End Sub
Private Sub Command4_Click()

    Call ZipFreeze(Me.hWnd, "d:\temp", "d:\temp\list.txt", "zipのパス")

End Sub

  




yahoo  google  MSDN  MSDN(us)  WinFAQ  Win Howto  tohoho  ie_DHTML  vector  wdic  辞書  天気 


[PROvbFunction]
CCBot/2.0 (https://commoncrawl.org/faq/)
19/04/22 15:28:41
InfoBoard Version 1.00 : Language=Perl

BatchHelper COMprog CommonSpec Cprog CprogBase CprogSAMPLE CprogSTD CprogSTD2 CprogWinsock Cygwin GameScript HTML HTMLcss InstallShield InstallShieldFunc JScript JScriptSAMPLE Jsfuncs LLINK OldProg OracleGold OracleSilver PRO PRObrowser PROc PROconePOINT PROcontrol PROftpclient PROjscript PROmailer PROperl PROperlCHAT PROphp PROphpLesson PROphpLesson2 PROphpLesson3 PROphpfunction PROphpfunctionArray PROphpfunctionMisc PROphpfunctionString PROsql PROvb PROvbFunction PROvbString PROvbdbmtn PROvbonepoint PROwebapp PROwin1POINT PROwinSYSTEM PROwinYOROZU PROwindows ProjectBoard RealPHP ScriptAPP ScriptMaster VBRealtime Vsfuncs a1root access accreq adsi ajax amazon argus asp aspSample aspVarious aspdotnet aw2kinst cappvariety centura ckeyword classStyle cmaterial cmbin cmdbapp cmenum cmlang cmlistbox cmstd cmstdseed cmtxt cs daz3d db dbCommon dbaccess dnettool dos download flex2 flex3 flex4 framemtn framereq freeWorld freesoft gimp ginpro giodownload google hdml home hta htmlDom ie9svg install java javaSwing javascript jetsql jquery jsp jspTest jspVarious lightbox listasp listmsapi listmsie listmsiis listmsnt listmspatch listmsscript listmsvb listmsvc memo ms msde mysql netbeans oraPlsql oracle oracleWiper oraclehelper orafunc other panoramio pear perl personal pgdojo pgdojo_cal pgdojo_holiday pgdojo_idx pgdojo_ref pgdojo_req php phpVarious phpguide plsql postgres ps r205 realC realwebapp regex rgaki ruby rule sboard sc scprint scquest sdb sdbquest seesaa setup sh_Imagick sh_canvas sh_dotnet sh_google sh_tool sh_web shadowbox shgm shjquery shvbs shweb sjscript skadai skywalker smalltech sperl sqlq src systemdoc tcpip tegaki three toolbox twitter typeface usb useXML vb vbdb vbsfunc vbsguide vbsrc vpc wcsignup webanymind webappgen webclass webparts webtool webwsh win8 winofsql wmi work wp youtube